Karmagination API
- DOM Methods
- Utilities
Attributes
The methods described will allow you to change the attributes of the elements.
attr( name )
Returns the attribute name's value of the first element.
<div title="fun"></div>alert(Karma('div').attr('title')); // fun
attr( name, value )
Change the attribute value of the elements.
<div></div>Karma('div').attr('title', 'fun'); alert(Karma('div').attr('title')); // fun
attr( object )
Iterate through the object key value pair and change the attribute value of the elements.
<div></div>Karma('div').attr({ 'title': 'fun', 'id': 'unique', 'lang': 'en' }); alert(Karma('div').attr('title')); // fun alert(Karma('div').attr('id')); // unique alert(Karma('div').attr('lang')); // en
addClass( string )
Adds string to the current class attribute
<div class="first"></div>Karma('div').addClass('another'); alert(Karma('div')[0].className); // "only another"
removeClass( string )
Removes string to the current class attribute
<div class="first second third"></div>Karma('div').removeClass('second'); alert(Karma('div')[0].className); // "first third"
hasClass( string )
Returns true if first element's class attribute contains string, else returns false
<div class="first second third"></div>alert(Karma('div').hasClass('second')); // true
toggleClass( string )
Removes string from class attribute if string is not found in the attributes, adds otherwise.
<div class="first second third"></div>Karma('div').toggleClass('second'); alert(Karma('div')[0].className); // "first third" Karma('div').toggleClass('second'); alert(Karma('div')[0].className); // "first third second"
val( )
val( name )
Gets the value of input elements
<input type="text" />Karma('input').val('hi'); alert(Karma('input').val()); // Hi