Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

testing jQuery selectors

 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1820
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also set one of these up for the chapter 2 example code of jQuery in Action (2nd ed) at http://www.bibeault.org/jqia2/chapter2/lab.selectors.html

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic