Square-bracket array notation to get a DOM element from a collection, e.g. collection[3]
. Since collections are extended JavaScript arrays, they behave similarly to standard arrays.
When an element method is used to create an element, the element will be wrapped in a collection. To access the DOM element within the collection, use collection[0]
:
var circle = Pablo.circle();
el = circle[0];
alert(el.nodeName); // 'circle'
When a collection contains multiple elements:
var collection = Pablo(['g', 'circle', 'line']);
el = collection[2];
alert(el.nodeName); // 'line'