my dog learned polymorphism
The moose likes HTML, CSS and JavaScript and the fly likes testing jQuery selectors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "testing jQuery selectors" Watch "testing jQuery selectors" New topic

testing jQuery selectors

J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 1522

This is probably one of those things that everyone except me already knows about, but I'm sharing it anyway because it's worth a bookmark.

I was struggling with a jQuery selector and went looking for a testing framework when I found this page. I'm not usually very impressed with the stuff from w3schools, but this is very handy.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Michael Matola
Ranch Hand

Joined: Mar 25, 2001
Posts: 1793
Why bother shuttling your HTML out to some external page?

For most of my purposes I just open the JavaScript console in the browser and do something like $('p').length; or $('p').css('border', 'solid 2px red'); Or depending on which browser you're using just $('p') will give you a handle on the set of elements, which you can then drill down through.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63849

I also set one of these up for the chapter 2 example code of jQuery in Action (2nd ed) at

But I also agree with Mike: sometimes it's easier just to do it locally on your own HTML using the JavaScript console. If this is not something you are familiar with, you should not write another single line of JavaScript until you learn to use it. It's the #1 best tool you need.

P.S. I avoid w3schools just on principle.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: testing jQuery selectors
It's not a secret anymore!