Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery in console not working properly

I'm using the jQueryify bookmarklet on a page so that I can call jQuery functions from the console. But everytime I invoke a jQuery function on a selected object, I get the error:

"TypeError: jQuery("li")[0].children[0].html is not a function
[Break On This Error] jQuery('li')[0].children[0].html();

I have tried this in FireBug as well as Google Chrome's Webkit console.

like image 657
Geo P Avatar asked Oct 24 '11 15:10

Geo P


1 Answers

You are no longer working with jQuery objects when using square braces.

jQuery("li")[0]

This returns you the 1st li as a DOMElement, not a jQuery object.

jQuery("li")[0].children[0]

This returns the 1st li's 1st child as a DOMElement, not a jQuery object.

.html()

This function only works for jQuery objects. For DOMElements, you can use the .innerHTML property.

I suggest instead of dealing with DOMElements, you should continue working with jQuery objects. Try using this instead:

jQuery('li').eq(0).children().eq(0).html()
like image 195
Rocket Hazmat Avatar answered Sep 28 '22 06:09

Rocket Hazmat