I have been using the YUI Selector Utility for a few months, but I just recently discovered how powerful it really is. I have been converting my imValidateForm JQuery plugin into a YUI widget. One of the validations this widget checks is whether a set of radio buttons are checked. I originally created validation object with pure Javascript. To determine whether the radio buttons were checked, I created the following code:
var flds = document.getElementsByName(‘gender’); var nL = flds.length; for (var j=0; j<nL; j++) { if (flds[j].checked) { ischecked = true; break; } } |
This is so verbose when compared to the YUI implementation of the same code:
var ischecked = (YAHOO.util.Selector.query('input[name=gender]:checked').length > 0) ? true : false; |
Not only am I able to use the CSS3 Attribute Selector and Pseudo-classes, I can combine the two to create more succinct code. Marvelous.


