Mantas Jonaitis Mantas Jonaitis - 15 days ago 5
Javascript Question

How to change specific href without having ID or name?

This is all I have. Is there any way to change href?

<a style="color: #0C82FD;" target="_blank" href="www.stapre.lt">www.stapre.lt</a>

Answer

You can use the attribute selector (by the way, href doesn't pre-suppose a protocol, so adding http:// is worthwhile):

<a style="color: #0C82FD;" target="_blank" href="http://www.stapre.lt">www.stapre.lt</a>

And then changing the href using prop():

$('a[href="http://www.stapre.lt"]').prop('href', 'http://google.com');

This of course assumes you don't have other <a> elements with the same href attribute value. If you do, you can then use index() to filter them down.