Elementals.js

Latest Version: 3.6.4 PRODUCTION 13 April 2018

Array _.ids

Summary:

An object of Elements where the index is an ID created by _.make or _.write or has been parsed from the initial document by including the data-elementals-idParse attribute on <body>.

Note that elements with ID's generated by other means will NOT be listed in this object.

The data-elementals-idParse attribute will only work if placed on <body> and can be quite time consuming given it has to walk EVERY element on the DOM. You should really only use this approach when the starting DOM is really tiny as it can turn elementals into a load-blocking script.

Note that this is NOT a collection, and any elements created with it will not be removed from this object in realtime. In most usage cases this doesn't matter, but it is something to be aware of.

Examples

// let's add a DIV#test to body
_.make('div#test', { last : document.body });
// show that yes the id was used to create a reference on _.ids
console.log(_.ids.test); 

You can also make all ID's that exist on the document be added to _.ids thusly:

<body data-elementals-idParse>
	<div id="test">This is a test</div>
	<script src="elementals.js"></script>
	<script>
		console.log(_.ids.test);
	</script>
</body>

This property was added in 3.6.1 as _.madeContent for testing purposes, but was not documented. In 3.6.2 the body parsing attribute was added and the name changed to _.ids.