Skip to content

Instantly share code, notes, and snippets.

@chrisdbasham317
Created August 26, 2019 16:54
Show Gist options
  • Save chrisdbasham317/970e23a1b26c516a3cdcb83ec85c7578 to your computer and use it in GitHub Desktop.
Save chrisdbasham317/970e23a1b26c516a3cdcb83ec85c7578 to your computer and use it in GitHub Desktop.
jQuery Selectors Guide

jQuery Selectors

Selecting HTML Elements by element name, ID, and class.

Element Name

$('[elementName]')

ID

$('#[IDName]')

Class

$('.[className]')

Chaining Selectors

You can chain multiple selectors in jQuery with a space. Ex: $('.bordered-content .ad-aside')

Selecting many elements with a single statement in jQuery.

You can select multiple elements in jQuery using a comma. Ex: $('#main, #secondary')

Selecting based on element attributes.

You can select an element based on attribute by having jQuery search for the specified element, attribute, and value with the following syntax: $([element][[attribute] = [value]] Ex: $('input[placeholder="Hello World"]')

Selecting based on the status of a checkbox/radio button.

To selected based on the status of a checkbox/radio button, one would use the [:checked] syntax. Ex: $('input:checked')

What does the jQuery Selector Return?

The jQuery Selector returns a jQuery Object wrapped around the element selected. Each time that element is selected , jQuery will make a unique object for that element. jQuery also gives this object access to its library of methods that can now be used to interact with the jQuery object.

Where to find jQuery docs.

Documentation can be found on https://api.jquery.com/

Searching api.jquery.com

Searching can be confusing on the website. If you know the specific method you are trying to find documentation on, the search bar is easy to use. If you are trying to describe the method you are looking for, it can be more difficult. This is because search results are ordered only by method name.

Searching google for answers about jQuery.

If you are looking for answers specific to jQuery on google; be sure to use 'jquery' in your search. Also, if at all possible, try to use method names specific to jquery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment