<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Skidoosh &#187; jQuery</title> <atom:link href="http://www.skidoosh.co.uk/category/jquery/feed/" rel="self" type="application/rss+xml" /><link>http://www.skidoosh.co.uk</link> <description>Skidoosh - PHP, Python, Django, Ruby on Rails Web Developer in North Wales</description> <lastBuildDate>Sat, 12 Jun 2010 09:08:31 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>jQuery selectors and attribute selectors reference and examples V2</title><link>http://www.skidoosh.co.uk/jquery/jquery-selectors-and-attribute-selectors-reference-and-examples-v2/</link> <comments>http://www.skidoosh.co.uk/jquery/jquery-selectors-and-attribute-selectors-reference-and-examples-v2/#comments</comments> <pubDate>Sun, 08 Nov 2009 13:38:05 +0000</pubDate> <dc:creator>Glyn Mooney</dc:creator> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://skidoosh.co.uk/?p=3</guid> <description><![CDATA[At the start of the year I wrote an article over on another site detailing the different methods you could use to select elements using the powerful jQuery attribute selectors. Because I no longer work for that company any more and the article is no longer being maintained, I've decided to create a second version of the article so I can update it and extend it's usefulness.]]></description> <content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"> <a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.skidoosh.co.uk%2Fjquery%2Fjquery-selectors-and-attribute-selectors-reference-and-examples-v2%2F"><br /> <img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.skidoosh.co.uk%2Fjquery%2Fjquery-selectors-and-attribute-selectors-reference-and-examples-v2%2F&amp;source=skidoosh&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br /> </a></div><p>At the start of the year I wrote an article over on another site detailing the different methods you could use to select elements using the powerful jQuery attribute selectors. Because I no longer work for that company any more and the article is no longer being maintained, I&#8217;ve decided to create a second version of the article so I can update it and extend it&#8217;s usefulness.</p><p>jQuery selectors and attribute selectors are some of the best features jQuery has to offer when it comes to DOM manipulation. They allow you to quickly select all elements or groups of element of a given tag name, attribute name or their contents and allow you to manipulate them as a group or a single node. This article can be used as a beginners guide to selectors or as a cheahsheet or reference.</p><p>The following table lists the different methods you have available to you to select nodes when using jQuery. All of the listed selectors should be wrapped in the following to stop your jQuery scripts conflicting with other libraries:</p><pre class="javascript">    (function ($) {
        //Your code here
    })(jQuery);</pre><h2>jQuery selectors and examples</h2><p>Below are a slip tabular list of the different selector and groups they seem to fit into.</p><ul><li><a href="#simple">jQuery Simple selectors</a></li><li><a href="#css">jQuery CSS style sudo selectors</a></li><li><a href="#xpath">jQuery XPath style selectors</a></li><li><a href="#form">jQuery form selectors</a></li></ul><p><a name="simple"> </a></p><div class="table-wrapper"><table border="0" summary=" jQuery Simple selectors"><caption> jQuery Simple selectors<br /></caption><thead><tr><th scope="col"> Selector</th><th scope="col"> Example</th><th width="40%" scope="col"> Description</th></tr></thead><tfoot><tr><td colspan="3">List accurate as of jQuery 1.3</td></tr></tfoot><tbody><tr class="odd"><th scope="row"> *</th><td>$(’*&#8217;);</td><td>This selector is a wild card method and will select all elements in a document.</td></tr><tr><th scope="row"> #id</th><td>$(’#id’);</td><td>This selector selects an element with the given ID.</td></tr><tr class="odd"><th scope="row"> .class</th><td>$(’.class’)</td><td>The class selector will gather all elements in the document with the given class name</td></tr><tr><th scope="row"> element</th><td>$(’element’)</td><td>This selector will collect all elements in a document with the given tag name i.e. table, ul, li, a etc.</td></tr><tr class="odd"><th scope="row"> a, b, c. … n</th><td>$(’th, td, .class, #id’)</td><td>This method can use multiple selection patterns to collect elements.</td></tr><tr><th scope="row"> parent child</th><td>$(’li a’)</td><td>This will select all “a” elements that are a descendant of “li”</td></tr><tr class="odd"><th scope="row"> a &gt; b</th><td>$(’table &gt; tr’);</td><td>This will select all b elements which are a child element of a or in our example all tr elements in a table or tables.</td></tr><tr><th scope="row"> a + b</th><td>$(’li + a’);</td><td>This will select all “a” elements that are an immediate descendant of “li” in our example.</td></tr><tr class="odd"><th scope="row"> a ~ b</th><td>$(’p ~ ul’);</td><td>This selector will select all “ul” elements that are a sibling of “p”</td></tr><tr><th scope="row"> :first</th><td>$(’ul li:first’);</td><td>Returns the first element in a result set</td></tr></tbody></table></div><p><a name="css"> </a></p><div class="table-wrapper"><table border="0" summary="jQuery CSS style sudo selectors"><caption> jQuery CSS style sudo selectors<br /></caption><thead><tr><th scope="col"> Selector</th><th scope="col"> Example</th><th width="40%" scope="col"> Description</th></tr></thead><tfoot><tr><td colspan="3">List accurate as of jQuery 1.3</td></tr></tfoot><tbody><tr class="odd"><th scope="row"> :first-child</th><td>$(’ul li:first-child’);</td><td>Returns the first child element of the parent element.</td></tr><tr class="odd"><th scope="row"> :last</th><td>$(’ul li:last’);</td><td>Returns the last element in a result set</td></tr><tr><th scope="row"> :last-child</th><td>$(’ul li:last-child’);</td><td>Returns the last child element of the parent element.</td></tr><tr class="odd"><th scope="row"> :only-child</th><td>$(’div p:only-child’);</td><td>Returns elements which are the only child of the parent element.</td></tr><tr><th scope="row"> :not(a)</th><td>$(’input:not(:checked)’);</td><td>Returns all elements that are <strong>not</strong><br /> “a” on in our example all input elements that are not checked</td></tr><tr class="odd"><th scope="row"> :has(a)</th><td>$(’div:has(p)’);</td><td>Returns all elements with a descendant that matches a in out example a “div” that contains a “p”.</td></tr><tr><th scope="row"> :odd</th><td>$(’ul li:odd’);</td><td>Returns all <strong>odd</strong><br /> elements in a result set (zero based)</td></tr><tr class="odd"><th scope="row"> :even</th><td>$(’ul li:even’);</td><td>Returns all <strong>even</strong><br /> elements in a result set (zero based)</td></tr><tr><th scope="row"> :eq(n)</th><td>$(’ul li:eq(n)’);</td><td>Returns a numbered element identified by n (zero based)</td></tr><tr class="odd"><th scope="row"> :gt(n)</th><td>$(’ul li:gt(n)’);</td><td>Returns all elements in a result set greater than n (zero based)</td></tr><tr><th scope="row"> :lt(n)</th><td>$(’ul li:lt(n)’);</td><td>Returns all elements in a result set less than n (zero based)</td></tr><tr class="odd"><th scope="row"> :nth-child(n)</th><td>$(’ul li:nth-child(n)’);</td><td>Returns the nth child in a result set (one based)</td></tr><tr><th scope="row"> :nth-child(odd)</th><td>$(’ul li:nth-child(odd)’);</td><td>Returns all <strong>odd</strong><br /> numbered elements in a result set (one based)</td></tr><tr class="odd"><th scope="row"> :nth-child(even)</th><td>$(’ul li:nth-child(even)’);</td><td>Returns all <strong>even</strong><br /> numbered elements in a result set (one based)</td></tr><tr><th scope="row"> :nth-child(formula)</th><td>$(’ul li:nth-child(3n)’);</td><td>Returns every nth child in a result set. In our example every third child (one based)</td></tr><tr class="odd"><th scope="row"> :header</th><td>$(’:header’);</td><td>Returns all heading elements e.g. h1, h2, etc.</td></tr><tr><th scope="row"> :animated</th><td>$(’ul:animated’);</td><td>Returns elements with an animation currently in progress</td></tr><tr class="odd"><th scope="row"> :contains(text)</th><td>$(’:contains(hello)’);</td><td>Returns all elements containing the passed string</td></tr><tr><th scope="row"> :empty</th><td>$(’:empty’);</td><td>Returns all elements that contain no child nodes</td></tr><tr class="odd"><th scope="row"> :parent</th><td>$(’li:parent’);</td><td>Returns all elements that a parent nodes to any other DOM element including text nodes.</td></tr><tr><th scope="row"> :hidden</th><td>$(’ul:hidden’);</td><td>Returns all hidden elements that are hidden with CSS or input fields of the type “hidden”</td></tr><tr class="odd"><th scope="row"> :visible</th><td>$(’ul:visible’);</td><td>Returns all visible elements</td></tr></tbody></table></div><p><a name="xpath"> </a></p><div class="table-wrapper"><table border="0" summary="jQuery XPath style selectors"><caption> jQuery XPath style selectors<br /></caption><thead><tr><th scope="col"> Selector</th><th scope="col"> Example</th><th width="40%" scope="col"> Description</th></tr></thead><tfoot><tr><td colspan="3">List accurate as of jQuery 1.3</td></tr></tfoot><tbody><tr class="odd"><th scope="row"> [attribute]</th><td>$(’[href]‘);</td><td>Returns all elements that contain the passed attribute in our example any element with a “href” attribute</td></tr><tr><th scope="row"> [attribute=value]</th><td>$(’[rel=external]‘);</td><td>Returns all elements that the passed attribute value is equal to the passed value. In our example ant element with a “rel” attribute equal to “external”</td></tr><tr class="odd"><th scope="row"> ['attribute!=value']</th><td>$(’[rel!=external]‘);</td><td>Returns all elements that the passed attribute value is not equal to the passed value. In our example ant element with a “rel” attribute that is not equal to “external”</td></tr><tr><th scope="row"> [attribute!=value]</th><td>$(’[class^=open]‘);</td><td>Returns all elements that the passed attribute value start with the passed value. In our example any element thats “class” attribute value begins with “open”</td></tr><tr class="odd"><th scope="row"> [attribute$=value]</th><td>$(’[id$=-wrapper]‘);</td><td>Returns all elements that the passed attribute value ends with the passed value. In our example any element whos “id” ends with “-wrapper”</td></tr><tr><th scope="row"> [attribute*=value]</th><td>$(’[class*=offer]‘);</td><td>Returns all elements that the passed attribute value contains the passed value. In our example any element whos “class” contains the string “offer”</td></tr></tbody></table></div><p><a name="form"> </a></p><div class="table-wrapper"><table border="0" summary="jQuery form element selectors"><caption> jQuery Form Selectors<br /></caption><thead><tr><th scope="col"> Selector</th><th scope="col"> Example</th><th width="40%" scope="col"> Description</th></tr></thead><tfoot><tr><td colspan="3">List accurate as of jQuery 1.3</td></tr></tfoot><tbody><tr class="odd"><th scope="row"> :input</th><td>$(’:input’);</td><td>Returns only input elements of the tag name input, select, textarea and button</td></tr><tr><th scope="row"> :text</th><td>$(’:text’);</td><td>Returns only input elements of the type “text”</td></tr><tr class="odd"><th scope="row"> :password</th><td>$(’:password’);</td><td>Returns only input elements of the type “password”</td></tr><tr><th scope="row"> :radio</th><td>$(’:radio’);</td><td>Returns only input elements of the type “radio”</td></tr><tr class="odd"><th scope="row"> :checkbox</th><td>$(’:checkbox’);</td><td>Returns only input elements of the type “checkbox”</td></tr><tr><th scope="row"> :submit</th><td>$(’:submit’);</td><td>Returns only input elements of the type “submit”</td></tr><tr class="odd"><th scope="row"> :image</th><td>$(’:image’);</td><td>Returns only input elements of the type “image”</td></tr><tr><th scope="row"> :reset</th><td>$(’:reset’);</td><td>Returns only input elements of the type “reset”</td></tr><tr class="odd"><th scope="row"> :file</th><td>$(’:file’);</td><td>Returns only input elements of the type “file”</td></tr><tr><th scope="row"> :button</th><td>$(’:button’);</td><td>Returns only input elements of the type “button”</td></tr><tr class="odd"><th scope="row"> :enabled</th><td>$(’:enabled’);</td><td>Returns all enabled input elements</td></tr><tr><th scope="row"> :selected</th><td>$(’:selected’);</td><td>Returns the <strong>selected</strong><br /> element in a select list.</td></tr><tr class="odd"><th scope="row"> :disabled</th><td>$(’:disabled’);</td><td>Returns disabled input elements</td></tr><tr><th scope="row"> :checked</th><td>$(’:checked’);</td><td>Returns checked input elements of the type radio or checkbox.</td></tr></tbody></table></div><p>Well I hope that version two of &#8220;jQuery selectors and attribute selectors reference and examples&#8221; is more helpful than V1. With a bit of luck you&#8217;ll find the grouping a little better too. Thanks for visiting! Please leave a message!</p> ]]></content:encoded> <wfw:commentRss>http://www.skidoosh.co.uk/jquery/jquery-selectors-and-attribute-selectors-reference-and-examples-v2/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 9/13 queries in 0.006 seconds using disk

Served from: www.skidoosh.co.uk @ 2010-09-08 16:46:19 -->