javascript - Jquery Select Dynamic ID -


i'm trying toggle visibility of this. you'll notice there's primary key number @ end of id:

<div id="campaign-details-container-12"> 

and how i've tried select it:

$(document).on("click",".show-details",function () {     $(this).blur();     var id = $(this).data("id");     var selector = "#campaign-details-container-"+id;     alert(selector);      $(selector).toggle();     return false; }); 

how can work? put data-id="12" tag in div instead , use class, how select that?

just select using attribute starts syntax:

$("[id^=campaign-details-container]"); 

no need go unnecessary things classes , id variables...

see http://www.w3schools.com/cssref/sel_attr_begin.asp


Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -