Skip to content

Instantly share code, notes, and snippets.

@SamuelColeman
Last active August 26, 2019 16:51
Show Gist options
  • Save SamuelColeman/c0a941ce9fffc682a6d492380f4e5415 to your computer and use it in GitHub Desktop.
Save SamuelColeman/c0a941ce9fffc682a6d492380f4e5415 to your computer and use it in GitHub Desktop.
Class questions for jQuery selectors

How do you select HTML elements using element names, ID, or class?

By name: $('h1')

By ID: $('#header')

By class: $('.important-header')

What are the different ways to chain selectors? For instance, how would you select an element that has a class of “bordered-content” AND “ad-aside”?

With a comma seperated list of selectors:

$('.bordered-content, .ad-aside')

How can you select many elements with different classes and IDs in a single selector statement? For instance, how can you select an element with the ID of “main” and a different element with an ID of “secondary”?

Using the same comma separated list of selectors:

$('#main, #secondary')

How do you select based on element attributes?

$('input[name='first_name']')

How do you select based on the state of a checkbox or radio button?

To select all checked input elements:

$(":selected")

What does the jQuery selector return? Be specific.

Selectors return a jQuery object known as the "wrapped set", which is an array-like structure that contains all the selected DOM elements.

Create a demo (in CodePen) explaining the use of different kinds of selectors.

https://codepen.io/samuelcoleman/pen/OJLprZj

Where do you go to find the official jQuery docs?

https://api.jquery.com/

What happens when you search for something on the jQuery docs page? Is it confusing? How are the results ordered?

It narrows down the results making it easier to find a method or property that you are looking for. It is not confusing becuase the results are ordered by most relevant to what you are searching.

Searching google for questions when you’re using jQuery can be tricky because it will turn up vanilla JavaScript results too. What are some strategies for using google to find answers regarding jQuery?

Too specify that you are looking for jQuery syntax when googling by including 'jQuery' somewhere in your search.

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