Tags
Asked 3 years ago
10 Jun 2021
Views 347
Jaydon

Jaydon posted

how to find element by text in jQuery ?

mostly we using the class or id to get any element or any other selector to get the element in jQuery
but is it possible to get the element by the text , i mean if it can search whole dom for given text and give me element which have that text
is it possible with text() method in jQuery or what ?
iptracker

iptracker
answered Jun 10 '21 00:00


use contains selector and get last element from the selector

 $(":contains('Questions'):last")


if you want to get all elements for given text than

 $(":contains('Questions')").each(function(){ 
console.log($(this))
})

Post Answer