Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery tr selection confusion

Tags:

html

jquery

I started working with jQuery again after a few months and am a little confused. I went to news.ycombinator.com, went to the console in chrome, and typed $('tr') to get an array of rows, but it only returned the first row (even though the first table has 3 rows).

When I type var x = $('tr:odd') in the chrome console, I get the error

Uncaught DOMException: Failed to execute 'querySelector' on 'Document': 'tr:odd' is not a valid selector.

Am I missing something obvious?

like image 272
user2635088 Avatar asked Dec 11 '25 21:12

user2635088


1 Answers

Want an array of all the "tr" tags?

The site doesn't use jQuery. Try with regular Javascript in the console:

document.getElementsByTagName("tr")

That will return an array with all the "tr" tags that exist in the DOM.

To use the "$" to select elements, the site must load jQuery on the header.

Now, what do you want to do with that selection?

like image 77
edd2110 Avatar answered Dec 15 '25 13:12

edd2110



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!