Reputation: 22926
If I have the following:
<div>Hello world</div>
How can I select the div using "Hello world" as the query value?
Upvotes: 0
Views: 355
Reputation: 3013
alternatively, you can use XPath:
$x('//div[text()="Hello world"]');
or, if you're not necessarily looking for the exact match:
$x('//div[text()[contains(., "Hello world")]]');
Upvotes: 1
Reputation: 68933
You can try with jQuery's :contains()
selector that selects all elements that contain the specified text:
console.log($('div:contains(Hello world)').get(0));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>Hello world</div>
Upvotes: 2