Class Index | File Index

Classes


Class $.dom.DOMTokenList

Represents a DOMTokenList object.
Defined in: core-dom.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
$.dom.DOMTokenList(elem, attr)
Creates a new DOMTokenList object.
Field Summary
Field Attributes Field Name and Description
 
The number of tokens in the current list.
Method Summary
Method Attributes Method Name and Description
 
add(token)
Add the token to the current list.
 
has(token)
Check if the token is in the current list.
 
item(index)
Retrieve the indexth token.
 
remove(token)
Remove the token from the current list.
 
toggle(token)
Toggle the presence of token in the current list.
 
Convert the current list to a string.
<private> <inner>  
<private> <inner>  
Class Detail
$.dom.DOMTokenList(elem, attr)
Creates a new DOMTokenList object.

The DOMTokenList interface is defined by the HTML 5 specification. It is used for all HTMLElements for the new classList property, and for other properties on other HTML elements.

This library implements the DOMTokenList interface, to be used in Web browsers which do not have it natively implemented. The level of the implementation should be close to a native one, in terms of usage from other scripts. However, it's slower and might have some "gotchas" in corner-cases.

// Let's work with the list of class names for the document body.
var elem = document.body;
var list = new $.dom.DOMTokenList(elem, 'className');
list.add('test');
list.add('test2');
list[0]; // returns 'test'
list.length; // returns 2
elem.className; // returns 'test test2'
list.toggle('test2'); // returns false
list.has('test2'); // returns false
list.has('test'); // returns true
list.remove('test');
Parameters:
{HTMLElement} elem
The element you want the DOMTokenList object for.
{String} attr
The attribute you want the DOMTokenList for.
Returns:
{DOMTokenList} The DOMTokenList object.
Field Detail
{Number} length
The number of tokens in the current list.
Method Detail
add(token)
Add the token to the current list.
Parameters:
{String} token
The token you want to add.
Throws:
{DOMException.INVALID_CHARACTER_ERR|Error}
If token contains a space character.

{Boolean} has(token)
Check if the token is in the current list.
Parameters:
{String} token
The token you want to check.
Throws:
{DOMException.INVALID_CHARACTER_ERR|Error}
If token contains a space character.
Returns:
{Boolean} True is returned if the token was found in the current list, otherwise false is returned.

{String} item(index)
Retrieve the indexth token.
Parameters:
{Number} index
The zero-based index/position of the token you want.
Returns:
{String} The token found at the index position in the list.

remove(token)
Remove the token from the current list.
Parameters:
{String} token
The token you want to remove.
Throws:
{DOMException.INVALID_CHARACTER_ERR|Error}
If token contains a space character.

{Boolean} toggle(token)
Toggle the presence of token in the current list.

If the token is found in the current list, it is removed. Otherwise, the token is added.

Parameters:
{String} token
The token you want to add/remove.
Throws:
{DOMException.INVALID_CHARACTER_ERR|Error}
If token contains a space character.
Returns:
{Boolean} True is returned if the token was added. Otherwise, false is returned.

{String} toString()
Convert the current list to a string. All the tokens are separated by a space character, something like "token1 token2 tokenn".
Returns:
{String} The list of tokens, separated by a space character.

<private> <inner> update()

<private> <inner> update_indexes()

Documentation generated by JsDoc Toolkit 2.1.0 on Thu Apr 23 2009 13:05:50 GMT+0300 (EEST)