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...
Comments
Post a Comment