javascript - function gets called even when the ID is not present in the document -


i have following javascript:

 $(document).ready(function () {     ...     $("#myselector").ready(function () {         window.alert('what hell!!!');     });  }); 

i expect pop window appear every time myselector appears somewhere in document.

the problem facing right code running (i pop up) when selector not exist in document.

why happening?

ready function executed when dom ready, ready event fired when don't pass arguments jquery, ie $().ready(), ignores selector. can use length property:

$(document).ready(function () {     if ( $("#myselector").length ) {        // ...     } }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -