i'm having little confusion around how selectors in javascript/jquery work. have 2 methods called in identical ways seem return different selectors , can't quite tell why.
if (document.url.indexof("search?s=") !== -1){ updateoldsearch(); } else { $("li a:contains('search')").bind("click", replacewithsearch); }
everything works fine in else statement here:
function replacewithsearch(){ this.parentnode.replacechild(searchwrapper, this); //works fine }
but when access in seems me identical way(clearly it's not identical) breaks
function updateoldsearch(){ var coursetab = $("li a:contains('search')"); coursetab.parentnode.replacechild(newbox, coursetab); //parentnode undefined }
any explanations happening behind scenes here? there automatic casting jquery i'm abusing?
in first example, this
represents native dom node. in second, coursetab
represents jquery object.
try second example:
function updateoldsearch(){ var coursetab = $("li a:contains('search')").get(0); coursetab.parentnode.replacechild(newbox, coursetab); }
Comments
Post a Comment