Total Page Preview:   000000000129

What is jQuery find() and get() method?

jQuery find() and get() method

find() method

In jQuery, the find() method is used to search for descendant elements that match a specified selector within the selected elements. It only searches for elements that are descendants of the elements matched by the original selector.

Here's the basic syntax of the find() method:
  • selector: A string containing a selector expression to match elements against.
  • filter: A string containing a selector expression to filter the descendant elements.
Here's an example using the find() method:
In this example, the find('li') method is used to search for all <li> elements within the element with the id 'container'. Then, the addClass('highlight') method adds a 'highlight' class to those found elements.

get() method

On the other hand, the get() method in jQuery is used to retrieve the DOM elements matched by the jQuery object. It allows you to access the underlying array of elements directly.
Here's the basic syntax of the get() method:
  • selector: A string containing a selector expression to match elements against.
Here's an example using the get() method:
In this example, the get() method is used to retrieve the underlying array of <li> DOM elements. The array is then passed to the $() function to create a new jQuery object, and the addClass('highlight') method is used to add a 'highlight' class to those elements.
Both find() and get() are useful methods in jQuery for manipulating and working with elements in the DOM.
 
 
 
 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments