Reputation: 309
I have this:
$(this).find('a:first');
and is working just fine to retrieve the URL of the first link, if the button I click is into the same container as the link I want to retrieve.
But how to retrieve the URL of the parent container?
In the bellow case, I want to retrieve the link of the a.sharedLink of the same <li>
the buttons are in. So if someone is clicking on one of those buttons, onclick event will capture the URL of the a.sharedLink. I have all the entire functionality, all I want is just to get that URL.
e.g:
<ul class="links">
<li><a class="sharedLink" href="http://www.domain1.com">Check out my hilarious personal website! :)</a>
<span class="buttons">
<a href="" class="share shareTW" target="_blank">Share on Twitter</a>
<a href="" class="share shareFB" target="_blank">Share on Facebook</a>
<a href="" class="share shareLI" target="_blank">Share on LinkedIn</a>
<a href="" class="share shareDE" target="_blank">Share on Delicious</a>
<a href="" class="share eMail" target="_blank">Send by E-Mail</a>
</span></li>
<li><a class="sharedLink" href="http://www.domain2.com">This is my Tech Blog</a>
<span class="buttons">
<a href="" class="share shareTW" target="_blank">Share on Twitter</a>
<a href="" class="share shareFB" target="_blank">Share on Facebook</a>
<a href="" class="share shareLI" target="_blank">Share on LinkedIn</a>
<a href="" class="share shareDE" target="_blank">Share on Delicious</a>
<a href="" class="share eMail" target="_blank">Send by E-Mail</a>
</span></li>
</ul>
Upvotes: 0
Views: 91
Reputation: 78650
$(this).closest('li').find('a:first');
http://api.jquery.com/closest/
Upvotes: 1