+ 2
SetAttribute in JS
I have writtena code, setAttribute not working there. Am I using it wrong.? https://code.sololearn.com/WlF8DQ5vNaol/?ref=app
5 Answers
+ 8
You have called more than one element in your code, thats the error. For this reason you need to choose one in this way with adding [0]:
document.getElementsByClassName("anchor")[0].setAttribute("href", "http://www.sololearn.com");
+ 5
Yes Khan that can be look like as in this example:
https://code.sololearn.com/WrvqlFKLSvdq/?ref=app
+ 5
Khan you are welcome. Happy coding!
+ 1
JaScript , So what if I have to change the href of all <a> tags?
Do I need a loop for that?
+ 1
JaScript , it's amazing. Thanks for your help