Mantas Jonaitis Mantas Jonaitis - 1 year ago 75
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=""></a>

Answer Source

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=""></a>

And then changing the href using prop():

$('a[href=""]').prop('href', '');

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.

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