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'); }); 

working example.

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -