How do I find the span containing the text "FIND ME"
<div> <span>FIND ME</span> <span>dont find me</span> </div>
Use the textContent property to get the text of a span element, e.g. const text = span. textContent . The textContent property will return the text content of the span and its descendants.
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
live('click',function(){ var parentDiv = $(this). closest('span'); alert(parentDiv); var curprice=parentDiv. find('span[id=span_view]'). val(); alert(curprice); });
http://api.jquery.com/contains-selector/
$("span:contains('FIND ME')")
ETA:
The contains selector is nice, but filtering a list of spans if probably quicker: http://jsperf.com/jquery-contains-vs-filter
$("span").filter(function() { return ($(this).text().indexOf('FIND ME') > -1) }); -- anywhere match $("span").filter(function() { return ($(this).text() === 'FIND ME') }); -- exact match
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