In this section, you will learn about jQuery selectors and how to lớn find DOM element(s) using selectors.
The jQuery selector enables you lớn find DOM elements in your web page. Most of the times you will start with selector function $() in the jQuery.
Bạn đã xem: Using jquery lớn find a class by id name
The selector expression parameter specifies a pattern khổng lồ match the elements. The jQuery uses CSS selector patterns as well as its own pattern khổng lồ match the elements.The context parameter is optional. It specifies elements in a DOM hierarchy from where jQuery starts searching for matching elements.
Let"s see commonly used selectors in jQuery.
The most common selector pattern is element name. Specifing an element name as string e.g. $("p") will return an array of all the elements in a webpage.
The following figure shows which DOM elements will be returned from $("p") & $"(div").
Bạn đang xem: Jquery selector, using jquery to find a class by id name
The following figure shows which DOM elements will be returned from $("#myDiv1") và $"(#prg2").
Xem thêm: 200+ Free Youtube To Mp4 - 200+ Free Youtube To Mp3 Converters
In the following example, jQuery returns all the elements that have class or contenteditable attribute irrespective of any value.