Tag Archive for 'jQuery'

CSS selectors with multiple HTML attributes

Something I had been banging my head about recently… CSS selectors on multiple attributes. No doubt, CSS selectors are powerful. Selecting on ids and classes are a cinch. And in case you didn’t know, you can string multiple classes together in a selection.

  1. div#id.class1.class2.class3

Note: You could probably string multiple ids in a selector, but most proper engines will barf at you or simply return nothing. Despite the utility in being able to select multiple elements by their respective ids in one selector, this is poor form. If you find yourself doing this often, you might want to give regularly selected groups of elements a common class.

But even more impressively, you can do this on other HTML attributes. (Especially useful in Selenium when trying to verify specific types of input fields.) I was trying to verify a specific UI interaction where a password field would be revealed as plain text when in focus and returns to an obfuscated password field on blur. Unfortunately, I couldn’t figure out how to verify that a SPECIFIC field needed to have both name=’myformfield’ AND type=’password’. A single attribute can be selected as the following:

  1. div#id.class1[name='myformfield']

Then it occurred to me that I might be able to string together multiple attribute selections similar to multiple class selections. Wouldn’t you know, it worked?! At least, it works in version 1.4.3 of jQuery’s Sizzle (its CSS selection engine) and 1.2.0 of Selenium IDE.

  1. div#id.class1[name='myformfield'][type='password']

Awesome. Hope this helps someone.

Excellent Javascript Library Comparison Chart!

Was browsing around on Noupe and stumbled across this fantastic chart and decided it needed to be shared with everyone. I’ve always wanted to see an apple-to-apples comparison of the these libraries. Learning new frameworks and understanding their quirks takes time and nothing beats first-hand experience, but this chart definitely gives you a good idea of what direction to start in.

Surprisingly, jQuery is at least twice as slow as every library listed according to this test and many more times that according to the chart. Still, comparing that with some of the syntax gymnastics you have to do to perform a simple selector (the most commonly performed task when dealing with DOM manipulation) with these other libraries, I’ll stick with my first love.

jQuery Crashcourse – a Screencast

I was asked to prepare a screencast which briefly describes jQuery, it’s selectors, and a few short examples. It was my first and I feel the results are pretty good. I did make a few mistakes regarding technical specifics and I tried to make note of it in the screencast. If there are any other items which I should have been more specific about or missed entirely, I am very interested in your thoughts.

I was having challenges embedding the video. You can see the screencast at http://www.nobulb.com/project/jquery_crashcourse/

You can also download the source code from the examples in the screencast or download the screencast itself.