Code has been added to clipboard!

jQuery .find() Explained: Learn to Find Children of Elements

Reading time 2 min
Published Jun 5, 2019
Updated Sep 30, 2019

The jQuery .find() is a method to retrieve descendants of elements according to the indicated selector. In other words, you can look through descendants of elements in the DOM tree. As a result, the function can generate an object, representing the detected elements.

This tutorial reviews the jQuery .find() function which might seem similar to the children() method. However, the children function is capable of only searching a single level down the DOM tree.

Continue reading this tutorial to learn how to jQuery find children according to the provided selector. While this function is used to retrieve children of elements, the .parent() function will also help jQuery find parents.

jQuery find: Main Tips

  • jQuery .find() method is applied when developers need to retrieve children of specified elements. The elements are searched according to the indicated selector.
  • After the jQuery find child function is applied and matches are detected, a new object is created to represent them.

.find() Explained

The method returns the direct children of the element you select, and uses syntax like this:

$(selector).find(selector | elements)

To illustrate how this method is used, we have a few examples:

Example
// returns all direct descendants

$(document).ready(() => {
  $("div").find("*").css({
    "color": "blue",
    "border": "2px solid green"
  });
Example
// returns all direct descendants that are <p> elements

$(document).ready(() => {
  $("div").find("p").css({
    "color": "blue",
    "border": "2px solid green"
  });

The jQuery find accepts one argument that can be one of two types: a selector or an element. In this context, elements can be jQuery objects or other DOM elements.

If you need to retrieve jQuery find parent of elements, you should take a look at the jQuery .parent() function. In cases when you need to jQuery find first child, you should include $(":nth-of-type") selector in the .find() function. It will retrieve the first children of their parents.

jQuery find: Summary

  • jQuery find method detects children of specified elements. The searching process depends on the selector expression.
  • The result of the jQuery find child function is an object, representing the discovered matches.
Learn jQuery
Introduction
Selectors
Events
Event Methods
Download
Callback
Chaining
Get and Set
Add Element
Remove Element
Traverse
Parent
Children
Sibling Traverse
Filtering
jQuery AJAX
Effects
Show and Hide
Fade Effect
Slide Effect
Animate Effect
Manipulate CSS
Width and Height
.addClass()
.after()
.animate()
.append()
.appendTo()
.attr()
.before()
.bind() (deprecated)
.blur()
.change()
.click()
.clone()
.css()
.dblclick()
.delay()
.delegate() and .undelegate() (deprecated)
.detach()
.empty()
.end()
.error() (deprecated)
.fadeIn()
.fadeOut()
.fadeTo()
.fadeToggle()
.finish()
.focus()
.focusIn()
.focusOut()
.hasClass()
.height()
.hide()
.hover()
.html()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.keypress()
.keyup()
.live() and .die() (deprecated)
.load() (deprecated)
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseout()
.mouseover()
.mouseup()
.off()
.offset()
.offsetParent()
.on()
.one()
.outerHeight()
.outerWidth()
.position()
.prepend()
.prependTo()
.prop()
.proxy()
.queue()
.ready()
.remove()
.removeAttr()
.removeClass()
.removeProp()
.replaceAll()
.replaceWith()
.resize()
.scroll()
.scrollLeft()
.scrollTop()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.submit()
.text()
.toggle()
.toggleClass()
.trigger()
.triggerHandler()
.unbind() (deprecated)
.unload() (deprecated)
.unwrap()
.val()
.width()
.wrap()
Event Properties
event.currentTarget
event.preventDefault()
event.relatedTarget
event.stopImmediatePropagation()
event.stopPropagation()
event.target
event.timeStamp
event.type
event.which
jQuery .find()
jQuery .keydown()
jQuery.noConflict()
pageY and pageX