How can I check via JQuery, if a object contains a string? For example I got this as a object:
<p>Lorem ipsum</p>
<p>Needle: in haystack</p>
<p>Anything: more text</p>
So now I want to check if this object contains one or more of this elements at the begining:
- "Needle:"
- "Something:"
- "Anything:"
In this case two elements are found in that object. Now I need the output in a variable of "Needle, Anything"
I tried to use :contains
and filter()
but I failed with that.
<script type="text/javascript">
$(function() {
var foundin = $('*:contains("Needle:")');
if (foundin) {
// extract part
}
});
</script>