esafwan esafwan - 6 months ago 8
HTML Question

Select all li with a particular <span> and get link info within

I want choose all the

<li>
in my html that have the
<span>Google Map</span>
in it and apply.

And get the value in href with jQuery. I tried going through jQuery docs but could not figure it out. Is this possible?

<li><span>Google Maps Staic Link:</span>
<a target="_blank" href="**Value To Get**" rel="nofollow">Map</a></li>


The actual HTML will be something like this.

<li><span>Name</span>Newyork:</li>
<li><span>Added:</span>23rd April</li>
<li><span>Google Map Link:</span>
<a target="_blank" href="**Value To Get**" rel="nofollow">Map</a>
</li>


From this I only want the one with Google Map Link. The link will change but the span
<span>Google Map Link:</span>
will not change.

Answer
$('span:contains("Google Map")').next('a').attr('href');

that will give you an jQuery array object of all the hrefs

Comments