+ Reply to Thread
Results 1 to 9 of 9

Thread: jQuery: Selectors

  1. #1
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    jQuery: Selectors

    G'day everyone.

    In this tutorial I will be teaching you all the selectors of jQuery. jQuery is a very powerful AJAX/Javascript based framework, that can be downloaded freely (link at the bottom of the tutorial). If you wish to use jQuery, you don't need to have any knowledge of Javascript at all. As long as you have 10 minutes you can learn it :) I am not joking! 10 minutes is all it takes!

    This is a fairly basic and straight forward reference, but I am writing this one so you can refer back to this when you stuck on my future tutorials. I hope to start writing many jQuery tutorials, so I am starting from the very basics.

    jQuery supports most of the CSS2 and CSS3 selectors, so if you already have a background in CSS, you have already got a head start.

    Enough chit chat and let's get started.

    Basics
    #id
    This will match any element with the given ID.

    element
    This will match any element supplied.

    .class
    This will match any element with the given class.

    *
    This will match any element, also known as the wildcard.

    Hierarchy
    ancestor descendant
    This will match any elements descendants of the ancestor given.

    parent > child
    This will match any elements child of the parent given. (similar to above)

    prev + next
    This will match any element that is given next to the previous. Both must be given.

    prev ~ siblings
    This will match any elements siblings after the previous element.

    Basic Filters
    :first
    This will match any first selected element given.

    :last
    This will match any last selected element given.

    :not(selector)
    This will filter out any given selector.

    :even
    This will match any even elements, zero indexed

    :odd
    This will match any odd elements, zero indexed.

    :eq(index)
    This will match a single element indexed by the given index.

    :gt(index)
    This will match all elements with the index above the given one.

    :lt(index)
    This will match all elements below the given one.

    :header
    This will match all header elements eg. h1, h2, h3 etc.

    :animated
    This will match all animated elements.

    Content Filters
    :contains(text)
    This will match all elements with the contained text.

    :empty
    This will match all elements that have no children. (includes text nodes)

    :has(selector)
    This will match all elements which contain at least one of the given selector.

    :parent
    This will match all elements which have children. (includes text)

    Visibility Filters
    :hidden
    This will match all elements that are hidden.

    :visibile
    This will match all elements that are visibile.

    Attribute Filters
    [attribute]
    This will match all elements with the given attribute.

    [attribute=value]
    This will match all elements with the given value that equals the given attribute.

    [attribute!=value]
    This will match all elements that do not have the given value that equals the given attribute.

    [attribute^=value]
    This will match all elements that either don't have the given attribute or do have the given attribute but not with a certain value.

    [attribute$=value]
    This will match all elements that have the given attribute and ends with the given value.

    [attribute*=value]
    This will match all elements that have the given attribute and it contains the given value.

    [attributeFilter1][attributeFilter2][attributeFilter3]
    This will match all elements that have the given attributes.

    Child Filters
    :nth-child(index/even/odd/equation)
    This will match all elements that are the nth-child of their parents or that their parent's even or odd children.

    :first-child
    This will match all the elements that are the first child of the given parent.

    :last-child
    This will match all the elements that are the last child of the given parent.

    :only-child
    This will match all the elements thare the the only child of the given parent.

    Forms
    :input
    This will match all the input, textarea, select and button elements.

    :text
    This will match all the input elements of type text.

    :password
    This will match all the input elements of type password.

    :radio
    This will match all the input elements of type radio.

    :checkbox
    This will match all the input elements of type checkbox.

    :submit
    This will match all the input elements of type submit.

    :image
    This will match all the input elements of type image.

    :reset
    This will match all the input elements of type reset.

    :button
    This will match all the button elements and input elements of type button.

    :file
    This will match all the input elements of type file.

    Form Filters
    :enabled
    This will match all elements that are enabled.

    :disabled
    This will match all elements that are disabled.

    :checked
    This will match all elements thare are checked.

    :selected
    This will match all elements that are selected.


    That is just about every selector jQuery supports. And as mentioned above, if you have a background of CSS, you already have a head start.

    Over the next couple of weeks, we will be using a fair bit of these selectors but not all of them. So you don't need to memorize them ;) It's a good idea to save them somewhere or even print them for easier finding :)

    I hope my next tutorial will be on adding certain CSS styles to a table row without having to write a class for each and every one of them ;)

    +rep if you found this information useful


    Regards,
    Brandon

    jQuery latest;
    Downloading jQuery - jQuery JavaScript Library
    Last edited by Jordan; 02-24-2009 at 07:26 AM.
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: jQuery: Selectors

    Nice tutorial Brandon. I've disabled smilies in your post because they were conflicting with the filter names.

    +rep

  4. #3
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: jQuery: Selectors

    I thought I put them in code tags. Thanks anyway Jordan
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  5. #4
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: jQuery: Selectors

    cool tutorial
    +rep
    yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  6. #5
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: jQuery: Selectors

    Thanks amro Glad you liked it.
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  7. #6
    Join Date
    Nov 2008
    Location
    Kosovo.
    Posts
    2,391
    Rep Power
    30

    Re: jQuery: Selectors

    Perfect Way to learn jQuery ...
    It's a great Tutorial for me !
    You Really deserve a +rep Brandon .. !

  8. #7
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: jQuery: Selectors

    Thanks mendim. If you liked this one, more are coming.
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  9. #8
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: jQuery: Selectors

    nice .. +rep when it lets me too .

  10. #9
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: jQuery: Selectors

    Thanks Egz. This is mainly a reference, but it will help you if you decide to do jQuery.
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 04-22-2011, 11:18 AM
  2. PHP / Jquery Help
    By tridiantgames in forum PHP Development
    Replies: 2
    Last Post: 08-31-2010, 09:40 PM
  3. CSS Part 3: CSS Selectors
    By Lop in forum Tutorials
    Replies: 3
    Last Post: 02-15-2010, 04:09 AM
  4. New to jQuery... need help
    By Anicho in forum JavaScript and CSS
    Replies: 1
    Last Post: 11-30-2009, 01:23 AM
  5. jQuery help
    By Jaan in forum JavaScript and CSS
    Replies: 7
    Last Post: 03-31-2009, 06:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts