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

Lists in Python -

android - can not access to progress bar in an other activity -

java - Vaadin 7 Pass Data Between Views -