esafwan esafwan - 2 years ago 58
HTML Question

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

I want choose all the

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>Added:</span>23rd April</li>
<li><span>Google Map Link:</span>
<a target="_blank" href="**Value To Get**" rel="nofollow">Map</a>

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 Source
$('span:contains("Google Map")').next('a').attr('href');

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download