I have a div
that contains paragraphs elements with text inside. Sometimes this text can be a link which I want to store in a var. I only want to select the link text, not the paragraph and not the div.
So here is an example of the HTML
<div>
<p>I have found a good review of a TV here <br>
https://www.avforums.com <!-- I want to select this text ---> <br>
This seems good to me!
</p>
</div>
If I do this:
if ( $("div:contains('http')") || $("div:contains('www')") ) {
var extractedLink = // select the link text and store it here
}
The problem is that I don't know how to select just the link text - it ends up selecting the entire <p>
or <div>
. The rules of a link are that it either begins with http or www and it has no spaces in it whatsoever. So I want to select just the string that contains http or www that has to spaces in it.
It sounds simple but I'm stuck!