Module 6 - Lesson 3

Methods for Selecting Elements

In this lesson, we’ll look into various methods of selecting elements, using the standard CSS selectors and also jQuery functions that allow you to traverse HTML documents to target any element you can think of.

Video Chapters

00:00 Introduction

01:08 jQuery Selectors

03:02 ID, Class, Pseudo-Class Selectors

04:37 Descendant Selectors

06:38 Header Selector

08:04 Traversing Selectors

12:22 Sibling Selector

13:43 Previous and Next Selectors

15:06 Further Resources

Sample selectors and traversal methods:

$('element, element, element') 		// select multiple elements
$('#id')							// select the CSS ID
$('.class')							// select the CSS class
$('parent > child')					// select direct children
$('ancestor descendant')			// select all descendants
$(':header')						// select all headings
$(':contains("text")')				// select elements which contain text
$('parent').find('selector')		// gets all selected children of the parent selector
$('parent').children() 				// gets selected children a single level down the DOM tree
$('child').parents()				// gets all the parent elements
$('child').parent()					// gets the parent a single level up the DOM tree
$('element').siblings()				// gets the sibling elements
$('element').prev()					// gets the immediately preceding sibling
$('element').next()					// gets the immediately following sibling

Join the discussion

Share your thoughts about this lesson with fellow students!

Login to your Account

If you're a DSA Student, please log in to your account to access the course content.

Sorry, you don't have access to this content.

It looks like you're not enrolled in Divi Stylist Academy.