0

Why is there an 's' in getElementsByTagName & in..... ByClassName and none in ... ById

21st Feb 2017, 5:39 PM
Elekwa Solomon
Elekwa Solomon - avatar
4 Réponses
+ 4
the primary reason why there is "s" within the command is because the "getElementsByTagName" returns an array of the tag(s). for example within a list you might have many list items and in that case, the "getElementsByTagName" will return an array with all those tags.
21st Feb 2017, 5:56 PM
Ousmane Diaw
+ 1
This is becouse there are many elements in document and there are many elements with the same class. Sow if you do this: var arr = document.getElementsByTagName("p") // you have an array with all "p" elements of your page. https://www.w3schools.com/tags/att_id.asp The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).
21st Feb 2017, 6:00 PM
Yurii Zadorozhnyi
Yurii Zadorozhnyi - avatar
+ 1
because the ID is unique on the DOM, but u can have different element with same class not the same ID
8th Mar 2017, 11:02 PM
Duperoy Dieuseul
Duperoy Dieuseul - avatar
0
supporting for 2 comments above getElementsByName with a "s" because you can put name to anchor for many time but getElementById means that you just can put 1 id and just 1
23rd Feb 2017, 1:48 AM
Thành Long
Thành Long - avatar