descendants

descendant Methods

.children()

  • Method is used to get the direct children of the selected element

Example

$(() => {
  $("button").click(() => {
    // this will add a border bottom
    // to all the children of the div element (the <p> elements)
    $('div').children().css("border-bottom", "3px double red")
  })
})

JS Bin on jsbin.com


.find()

  • Method is used to get the descendant elements of the selected element

  • The find() and children() methods are similar, except that the find() method search through multiple levels down the DOM tree to the last descendant, whereas the children() method only search a single level down the DOM tree

Example

$(() => {
  $("button").click(() => {
    // this will add a border bottom
    // to all spans within the div element
    $('div').find('span').css("border-bottom", "3px double red")
  })
})

JS Bin on jsbin.com