Get tag abbreviation element?

I don’t know what he called, but I know that there is a way to get elements based on their tags without getElementsByTagName . It returns the same, but it is shorter, and I use tags a lot in my project. I mean document.frames[x] and document.images[x] , but with other elements like document.b[x] or document.a[x] . Since document.images does not match the <img> , it seems that if there are more, they will be named differently. Will anyone know what he named when using this method and / or have a list of accepted tags? Thanks.

PS Please do not suggest using a library such as jQuery. This project is for training, so I want to use plain JavaScript.

+4
source share
3 answers

As mentioned in other answers, this has nothing to do with JavaScript, these are the DOM properties and methods available through the JavaScript language binding for the DOM .

As for addressing elements such as document.frames[x] (note that this is not true, it should be window.frames[x] ) and document.images[x] are Document Object / HTML Collections , and the W3C standard includes only images, applets, links, forms and anchors .

So, if I don’t look in a completely wrong place, from what I can say from DOM-1 and DOM-2 , it seems that some way of randomly addressing elements by tag name is not used.

Update

writing MDC to HTMLCollection more understandable; he reads

Listed below are each element (and its specific properties) that return an HTMLCollection: Document (images, applets, links, forms, bindings); form (elements); map (area); table (rows, tBodies); tableSection (rows); row (cells)

+6
source

Besides the other JavaScript libraries that create these shortcuts, I don't know any built-in language. It would be trivial to compare this with your own abbreviation:

 var $ = document.getElementsByTagName; // you can then use it like so: $('SPAN').// and so on 

In addition, there is no access to all tags in the document built into the array:

http://www.javascriptkit.com/jsref/document.shtml

+5
source

Create your own link,

 document.tag = document.getElementsByTagName; 

or wrapper

 function tag(name) { return document.getElementsByTagName(name); } 

The only APIs that I know about this query support by element name,

Dom

getElementsByTagName

CSS selectors

querySelectorAll

XPath

evaluate

E4x

(only mozilla and not yet working with the DOM)

+2
source

All Articles