cssQuery()isapowerfulcross-browserJavaScriptfunctionthatenablesqueryingofaDOMdocumentusingCSSselectors.AllCSS1andCSS2selectorsareallowedplusquiteafewCSS3selectors.
Usage
Syntax
elements=cssQuery(selector[,from]);whereselector(required)isavalidCSSselectorandfrom(optional)isadocument,elementorarrayofelementswhichisfilteredbyselector.
ThefunctionreturnsaJavaScriptarrayofelements.Ifthereisnomatch,anemptyarrayisreturned.
Someexamples:
//findallparagraphsthataredirectdescendants//ofthedocumentbodyvartags=cssQuery("body>p");//findallelementswiththe"href"attributevartags=cssQuery("[href]");//findallanchorelementswith"href"equalto"#"vartags=cssQuery("a[href='#']");//findallimagescontainedbytheaboveanchorsvarimages=cssQuery("img",tags);//findalllistsvartags=cssQuery("dl,ol,ul");//queryanexternalxmldocumentvartags=cssQuery("my|:root>my|link",myXMLDoc);//justplaincomplicatedvarcomplex="p>a:first-child+input[type=text]~span";vartags=cssQuery(complex);AllowedSelectors
*
E
EF
E>F
E+F
E~F
E.warning
E#myid
E:link
E:first-child
E:last-child
E:nth-child(n)
E:nth-last-child(n)
E:only-child
E:root
E:lang(fr)
E:target
E:enabled
E:disabled
E:checked
E:contains("foo")
E:not(s)
E[foo]
E[foo="bar"]
E[foo~="bar"]
E[foo^="bar"]
E[foo$="bar"]
E[foo*="bar"]
E[foo|="bar"]
Compatibility
Knowntoworkonthefollowingplatforms:
MicrosoftInternetExplorer5+(Windows)
MicrosoftInternetExplorer5.2(Mac)
Firefox/Mozilla1.6+
Opera7+
Netscape6+
Safari1.2