#A tiny JavaScript DOM library Utilities methods & DOM elements decorator ##Examples
jArgon.trim(' a string to trim ');
var jargonObj = jArgon('div > div.foo .bar #jargon');
jargonObj.getElementsByAttribute('.fuzz[bar]');
##Test suite
Use Qunit, see test/
directory.
Tested under:
- FF, Chrome on Ubuntu 12.04
- IE7+, Chrome, FF, Opera on Windows 7
- Safari on iOS
- Android Browser, Chrome on Android 4.03
##Coding convention
I use my own .jshintrc
file, but rules similar to jQuery's
##Documentation: JSDoc, markdox for generating README.md
Extend an object with a set a properties ##Example
var o = { prop1: 'hello' };
jArgon.extend( o, { prop2: 'world' } );
// o = { prop1: 'hello', prop2: 'world' }
-
Object target - The target object to extend
-
Object extension - An object containing the new properties
- Object - The target object extended
Call native API method if exists, use fallback otherwise
- String str - The string to trim
- String The new trimmed string
Convert pseudo arrays (eg arguments
, nodeList
) to arrays
- PseudoArray pseudoArray - The pseudoArray to convert
- Array The new array
Iterate over a jargon instance, executing a function for each elements. The function context is a jargon object wrapping the element itself. ###Example
// add classname 'fuzz' on all p tags
jArgon('p').each(function() {
this.addClassName('fuzz');
});
- Function fn - The function which will be executed recursively
- jArgon The jargon instance on which the method is called
Check if a jargon instance has a given element's name. If the jargon instance contains multiple elements, an array will be return containing a boolean for each elements ###Example
jArgon('.current').hasName('div');
- String name - The element name
- Array|Boolean True if match, false otherwise
Check if a jargon instance has a given class name. If the jargon instance contains multiple elements, an array will be return containing a boolean for each elements ###Example
jArgon('#nav-bar').hasClassName('hidden');
- String className - The class name
- Array|Boolean True if match, false otherwise
Check if a jargon instance has a given selector If the jargon instance contains multiple elements, an array will be return containing a boolean for each elements ###Example
jArgon('a').hasSelector('.foo[href="fuzz"]');
// Supported selectors are :
// '#foo', 'div', '.foo', '.foo[href]', 'div[href]', 'div.foo',
// 'div[href="bar"]', '.foo[href="fuzz"]'
- String selector - The selector
- Array|Boolean True if match, false otherwise
Get the child elements of a jargon instance which match a class name. If the jargon instance contains multiple elements, the resulting child elements are merged into a single array. ###Example
var ulElem = jArgon('ul');
// return children li elements with class 'current'
ulElem.getElementsByClassName('li.current');
// Valid selectors are :
// 'div.foo' or '.foo' or 'foo'
- String selector - The selector
- jArgon jArgon object containing matching elements
Get the child elements of a jargon instance which match an attribute. If the jargon instance contains multiple elements, the resulting child elements are merged into a single array. ###Example
var artElem = jArgon('article');
// return children a elements with href="#"
artElem.getElementsByAttribute('a[href="#"]');
// Valid selectors are :
// 'a[href]' or '.foo[href]' or 'a[href="bar"]' or '.foo[href="bar"]'
- String selector - The selector
- jArgon jArgon object containing matching elements
Add a class name to the elements of a jargon instance. If the class name already present, do nothing.
// Valid class name:
// 'foo'
- String className - The class name
- jArgon jArgon object with the updated elements
Remove a class name to the elements of a jargon instance. If the class name not present, do nothing.
// Valid class name:
// 'foo'
- String className - The class name
- jArgon jArgon object with the updated elements
Toggle a class name on the elements of a jargon instance.
// Valid class name:
// 'foo'
- String className - The class name
- jArgon jArgon object with the updated elements
###jArgon initializer Use cases:
- Query document's elements on a CSS selector chain and return a jArgon instance which wraps matching elements. Based on a "document only bottom-up algorithm"
- Wrap a single HTMLElement or a NodeList into a jArgon instance.
If the selector mismatch or if the element is unvalid, an empty jArgon object is returned.
var jargonObj;
// a valid selector chain:
jargonObj = jArgon('div > div.foo .bar .fuzz[bar] > a[href="javascript.html"] #jargon');
// elem is a valid HTMLElement
jargonObj = jArgon( elem );
// elems is a NodeList
jargonObj = jArgon( elems );
- String|HTMLElement|NodeList selector - The selector
- jArgon jArgon object containing matching elements or the passed element(s)