Constructor

The Karmagination constructors are ordered by how processing-intensive they are (during normal usage) with Karma() being the lightest and Karma(selector) being the heaviest.

Karma( )

Karma() is an alias for Karma(document). Please view Karma(element) below for more information.

alert(Karma()[0] === document); // true

Karma( element )

Enable Karmagination's methods on the DOM element.

Parameters:

<div id="example1">This is one</div>
var $myDiv = Karma(document.getElementById('example1'));
 
alert($myDiv[0].innerHTML); // This is one
alert($myDiv[0].id);        // example1
alert($myDiv[0].nodeName);  // DIV

Karma( elements )

Enable Karmagination's methods on the array of DOM elements.

Parameters:

<div id="example1">This is one</div>
<div id="example2">This is two</div>
<div id="example3">This is three</div>
var myDiv = [ document.getElementById('example1'), 
              document.getElementById('example2'), 
              document.getElementById('example3') ];
 
var $myDiv = Karma(myDiv);
 
alert($myDiv[0].innerHTML) // This is one
alert($myDiv[1].id)        // example2
alert($myDiv[2].nodeName)  // DIV

Karma( callback )

Runs the callback function once the all the DOM structure in the current document is ready to be modified. Why not window.onload? Because usually the DOM is ready even before all the heavy images are loaded (FYI, images takes a long time to load).

Parameters:

Karma(function($){
  alert($('#example1').html()); // Hi
});
<div id="example1">Hi</div>

Karma( html, [context] )

Creates DOM nodes within the context specified from the HTML provided. The created nodes will have access to Karmagination's methods. For this to work, the html must be well formed be encased in the tags. Due to performance issues, Karmagination will not check the validity of the HTML.

Parameters:

This code will work.

var created = Karma('<div class="madeup">Hi How are you</div>');
alert(created[0].nodeName); // DIV

This will throw an error because there are text not wrapped in HTML tags.

var created = Karma('Goodbye<div class="madeup">Hi How are you</div>'); // error

Karma( selector, [root] )

Gets all the elements that matches the CSS selector that exists under the root element. The selected elements will return gain access to Karmagination's methods. Here are the list of selectors supported by Karmagination, it has almost the same selector set as jQuery because Karmagination uses Sizzle.

Parameters:

<div class="not_selected">Hi</div>
<div id="root" class="root">
 <div class="selected">Hi</div>
 <div class="selected_also">Hi</div>
</div>
var selected = Karma('div', document.getElementById('root'));
 
alert(selected[0].className); // selected
alert(selected[1].className); // selected_also
 
var allDiv = Karma('div');
 
alert(allDiv[0].className); // not_selected
alert(allDiv[1].className); // root
alert(allDiv[2].className); // selected
alert(allDiv[3].className); // selected_also