Sometimes you need to do something with every instance of a particular HTML element on a page. For example, you could change the font on every <textarea>
. The easiest way to do this is to call getElementsByTagName('tagname')
, which returns a collection you can loop through.
Example: Find all the textareas on a page
var allTextareas, thisTextarea; allTextareas = document.getElementsByTagName('textarea'); for (var i = 0; i < allTextareas.length; i++) { thisTextarea = allTextareas[i]; // do something with thisTextarea }
You should not use this pattern to do something to every link on the page, because the |