I want to select an element based on their innertext in JQuery. Below is my Html
<html>
<body>
<a href="fddf">4</a>
<a href="fddf">4</a>
<a href="fddf">4</a>
</body>
</html>
I want to select all the <a>
tags which has text of "4". Any idea how do I do it?
The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.
To check if a div element contains specific text:Use the textContent property on the element to get the text content of the element and its descendants. Use the includes() method to check if the specific text is contained in the div . If it is, the includes() method returns true , otherwise false is returned.
The CSS id Selector The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
You're looking for the :contains
selector, like this:
$('a:contains("4")')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With