iman aletaha
iman aletaha

Reputation: 31

how select a dynamic id generated in php with jquery

this code generated in php id="sus- ... <--- is static and id="sus-d->id ?>" is my problem to select that

<button class="btn btn-danger btn-xs" id="sus-<?= $D->d->id ?>" ><i class="icon-trash "></i></button>

out put :

id="sus-2131"

so i want select all id's start with

sus-

with below function :

jQuery('#sus-').btsConfirmButton({msg:"I'm sure!"}, function(e) {
        d_manage('delete','<?= $D->d->id?>');$(this).slideUp();
    });

that it !

Upvotes: 0

Views: 254

Answers (3)

Gary Storey
Gary Storey

Reputation: 1814

Use the attribute selector:

$('[id^=sus]').btsConfirmButton({msg:"I'm sure!"}, function(e) {
   d_manage('delete','<?= $D->d->id?>');$(this).slideUp();
});

Upvotes: 0

AmmarCSE
AmmarCSE

Reputation: 30567

Use the starts with selector ^= like

jQuery('[id^="sus-"]').btsConfirmButton({msg:"I'm sure!"}, function(e) {
        d_manage('delete','<?= $D->d->id?>');$(this).slideUp();
    });

Upvotes: 1

drsnark
drsnark

Reputation: 3033

If you made each item use the css class "sus" instead you might be able to select them all with something list $('.suss').each()...

You would then be able to iterate over each "sus" item.

Hope this helps.

Upvotes: 0

Related Questions