Using jQuery, while in the span element, without knowing post-383 id and class, how can I retrieve the url within the h2 a element?
The html code:
<div id="post-1383" class="post-1383>
<h2 class="entry-title">
<a href="http://example.com/soul-music/">Soul Music</a>
</h2>
<span class="btn"></span>
</div>
Something like this?
$('.btn').previous('a').attr('href');
Thanks!
You can do it using
.prev()and.find()or.children(), like this:You can give it a try here. The
<a>isn’t a sibling so.prev()won’t won’t work, you have to go back to the<h2>which is a sibling, then go inside it to get the<a>itself.