javascript - Selecting a generated id with jQuery -
i have html element this:
<div id="myelement_9082173219731721923"> i want add class element select css. loaded after other stuff on site, because it´s generated external javascript. that´s why tried:
$('[id^="myelement_"]').load(function() { alert("im here"); $('[id^="myelement_"]').addclass('myclass'); }); but doesn´t reach alert. doing wrong? thanks
this should work, load on div element never happen. use dom change listener instead. , don't need quotes around id selector. not wrong, not must have.
$("body").on("domsubtreemodified", function() { $('[id^="myelement_"]').addclass('myclass'); }); you should change body smallest selector of dom, div#myelement_ appear. , if happens 1 time, change on one. listener disables , not run on changes.
Comments
Post a Comment