Hardy Hardy - 1 year ago 65
HTML Question

how to select id which is dynamically change in jquery?

here is my html:

<?php echo ($row['status'] == 1)? ?>
<span id='slide_".$row['id']."' name="slid_id" class='label label-danger'>Inactive</span>
<?php : ?>
<span id='slide_".$row['id']."' name="slid_id" class='label label-success'>Active</span>
<?php ; ?>

here is my jquery code:


var id = $(":input[name=slide_id]").val();

i didn't get anything , i want to get the

ID & its dynamic generated value

of the span element and then perform some action like on click i want to change the status from active to inactive or vise versa.

thanks in advance.

Answer Source

Your HTML is missing from the question, but eliminating the colon in your jQuery selector might do the trick in selecting an input field - i.e. $("input[name=slide_id]").val().

If you want to get the ID attribute of a span element, this would work:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download