2

Using jQuery and given this

<ul>
<li>
<a external="http://stackoverflow.com" href="home.htm">Link 1</a>
</li>
<li>
<a href="about.htm">Link 2</a>
</li>
<li>
<a external="http://google.com" href="contact.html">Link 3</a>
</li>
</ul

I want to grab the links with a attribute of "external". Use the value of the external attribute to update the href.

So link 1 and 3 should end up pointing to stackoverflow.com and google.com respectively.

1

2 Answers 2

11
$('a[external]').each(function(i, el){
  $(el).attr('href', $(el).attr('external'));
});
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Just what I needed. Will accept your answer after 9 minutes.
1

Put this in $(document).ready body:

$('li a[external]').each(function() {
   var ext = $(this).attr('external');
   $(this).attr('href', ext);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.