<div id="foo" > this is the content of div "foo" </div>
<div id="foo2"> this is the content of div "foo2" </div>
<pre>
<h3>accepts element id</h3>
myLibrary('foo')
<h3> accepts objects</h3>
myObject = document.getElementById('myElement');
myLibrary( myObject )
<h3>accepts arrays of id's</h3>
idArray = [ 'foo' , 'foo2' ];
myLibrary( idArray )
<h3>accepts mixed arrays</h3>
myObject = document.getElementById('myElement');
idArray = [ 'foo' , 'foo2' , myObject ];
myLibrary( idArray );
<h3>accepts multiple arguments as id's</h3>
myLibrary( 'foo' , 'foo2' )
<h3>accepts multiple arguments as objects</h3>
myObject = document.getElementById('myElement');
myLibrary( myObject );
<h3>accepts mixed arguments</h3>
myObject = document.getElementById('myElement');
myLibrary( 'foo' , 'foo2' , myObject )
<h3>Not supported</h3>
If multiple arrays are provided as arguments only the first one is used.
Arrays with arrays dont work.
</pre>
CSS
h3{ color:red;background:yellow; }
body { background:#331; color:#fff; }
JavaScript
myLibrary = function (e) {
/* accepts dom referrences in the form of:
objects,
id (as a string),
array of id,
arrays of objects,
arrays of id's mixed with objects,
multiple arguments (as if an array),
*/
e = ( arguments.length > 1 ) ? [].slice.call(arguments) : (Array.isArray(e)) ? e : [e];
for ( a in e ){ myObj = (typeof e[a] === "string") ? document.getElementById(e[a]) : e[a];
/* do your something with myObj */
alert(myObj.innerHTML);
}
}
myLibrary('foo','foo2');
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.