I have such code:
<li class="myClass">
<a href="www.example.com">link</a>
</li>
I need to change href attribute to www.example2.com How would I achieve that using javascript?
I have such code:
<li class="myClass">
<a href="www.example.com">link</a>
</li>
I need to change href attribute to www.example2.com How would I achieve that using javascript?
You could use document.querySelector
:
document.querySelector('.myClass a').href = 'www.example2.com'
Javascript was originally designed to access the DOM on websites, so you would need to find the element within document
. There are a bunch of ways to do it. Check out all the methods that start with "get" here: http://www.w3schools.com/jsref/dom_obj_document.asp.