Using jQuery, I'm trying to target all paragraph elements that only contain a child anchor element (as a direct descendent) AND that have no text nodes outside of that child element, eg:
<p><a href="http://...">Some link</a></p>
I've tried jQuery's only-child
selector, but text nodes obviously aren't treated as child elements. I've also looked at contents()
and presume I could target anchor elements whose opening tag is the first node. However, on the latter, the site I'm building is a blog that others will be writing for using a CMS and so I can't ensure they won't begin a regular paragraph with a link, which would add unwanted styling.
I'm relatively new to jQuery - about one month. Just so you know...
Thanks!