0

In my site I have one div like this

<div class="yjme_item_in yjmeitem29">

inside this div there is a link and I would like to replace the href of it, introducing www.google.com.

Any ideas ?

I have tried this with no luck

var a = document.getElementsByClassName("yjmeitem29")[0];
a.setAttribute("href", "www.google.es");
user204415
  • 307
  • 1
  • 4
  • 20

1 Answers1

1

Try this

a.childNodes[0].setAttribute("href", "www.google.es");
naota
  • 4,695
  • 1
  • 18
  • 21
  • Word of caution, using `childNodes` in situations like this can fail quite unexpectedly (unexpected by some), if there is any whitespace between the parent element’s and the child’s opening tag. – CBroe May 27 '14 at 01:38