+ 1
how getElementByTagName retuns value for links?
suppose I have 500 lines of code in html and many links are there... And I want to change Nth link using JS, so do I have to count the value of N.... because the getElementByTagName would return an array of all the links ?
4 ответов
+ 2
Well in that case if you know which element is (nth), just specify it like an array.
If not, loop through them all checking if the href is the one you are looking for.
I strongly recommend you using an if on that tag to make it easier.
And also to check out the document.querySelector
+ 2
Of course you need to give the count to program, otherwise how does program know which link to access?
Or just assign an id to the selected link, use getElementById to access it.
+ 1
the getElementById method is supposed to return only one element, because the id is not meant to be repeated to avoid this particular problem. But if it does return an array as you say, you'll have to specify which one
+ 1
noname sorry, I wanted to ask about getElementByTagName ... when tag is <a> .
P.S. I have edited the question.