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 -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -