Kimbo.js API Documentation

$#Defined in: kimbo.js:16

Global namespace for using Kimbo functions

$.ajax([options])#Defined in: kimbo.js:2964

Perform an asynchronous HTTP (Ajax) request.

Parameters

options
object optional
An object with options

Returns object The native xhr object.

Usage

Get a username passing an id to the /users url

$.ajax({
  url '/users',
  data: {
    id: 3
  },
  success: function (response, responseMessage, xhr, settings) {
    // Success...
  },
  error: function (response, responseMessage, xhr, settings) {
    // Error...
  }
});

$.ajaxSettings#Defined in: kimbo.js:2912

Default ajax settings object.

Usage

If you want to change the global and default ajax settings, change this object properties:

$.ajaxSettings.error = function () {
  // Handle any failed ajax request in your app
};
$.ajaxSettings.timeout = 1000; // 1 second

$.camelCase(str)#Defined in: kimbo.js:2106

Camelize any dashed separated string

Parameters

str
string
A dashed separated string value to transform into camelCase.

Returns string camelCase string

Usage

$.camelCase('background-color');

Result:

'backgroundColor'

$.extend(target, [objectN])#Defined in: kimbo.js:268

Merge the contents of two or more objects together into the first object.

Parameters

target
object boolean
Object that will receive the merged properties if objects are passed, or target will extend Kimbo object. If target is true the passed objects will be recursively merged.
objectN
object optional
One or more objects with additional properties.

Returns object The extended target or a new copy if target is an empty object.

Usage

When passing two or more objects, all properties will be merged into the target object.

var obj1 = { msg: 'hi', info: { from: 'Denis' }};
var obj2 = { msg: 'Hi!', info: { time: '22:00PM' }};

// Merge obj1 into obj2
$.extend(obj1, obj2);

// Now obj1 is equal to:
{ msg: 'Hi!', info: { time: '22:00PM' }}

If an empty target object is passed, none of the other objects will be directly modified

// Pass an empty target
var obj3 = $.extend({}, obj1, obj);

To do a recursive merge, pass true as first argument, then the objects to merge

$.extend(true, obj1, obj2);
// Obj1 will be:
{ msg: 'Hi!', info: { from: 'Denis', time: '22:00PM' }}

$.forEach(obj, callback)#Defined in: kimbo.js:218

Iterator function that can be used to seamlessly iterate over both objects and arrays.

Parameters

obj
object
Object or array to iterate
callback
function
Function that will be executed on each iteration

Returns object The original array or object

Usage

// Iterating array
$.forEach(['a', 'b', 'c'], function (index, value) {
  alert(index + ': ' + value);
});

// Iterating object
$.forEach({name: 'Denis', surname: 'Ciccale'}, function (key, value) {
  alert(key + ': ' + value);
});

$.get(url, [data], callback, [type])#Defined in: kimbo.js:3062

Load data from the server using HTTP GET request.

Parameters

url
string
A string containing the URL to which the request is sent.
data
string object optional
An option string or object with data params to send to the server.
callback
function
A callback function to execute if the request succeeds.
type
string optional
String with the type of the data to send (intelligent guess by default).

Usage

$.get('url/users.php', { id: '123' }, function (data) {
  // Success
  console.log('response:', data);
});

This method is a shorthand for the $.ajax

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

$.getJSON(url, [data], callback, [type])#Defined in: kimbo.js:3156

Load data from the server using HTTP POST request.

Parameters

url
string
A string containing the URL to which the request is sent.
data
string object optional
An option string or object with data params to send to the server.
callback
function
A callback function to execute if the request succeeds.
type
string optional
String with the type of the data to send (intelligent guess by default).

Usage

$.getJSON('url/test.json', { id: '2' }, function (data) {
  // Success
  console.log('response:', data);
});

This method is a shorthand for the $.ajax

$.ajax({
  url: url,
  dataType: 'json',
  success: success
});

To get json data with jsonp:

$.getJSON('http://search.twitter.com/search.json?callback=?', 'q=#javascript', function (data) {
  console.log(data);
});

$.getScript(url, callback)#Defined in: kimbo.js:3127

Load a JavaScript file from the server using a GET HTTP request, then execute it.

Parameters

url
string
A string containing the URL to which the request is sent.
callback
function
A callback function to execute if the request succeeds.

Usage

$.getScript('url/script.js', function (data) {
  // Success
  console.log('response:', data);
});

This method is a shorthand for the $.ajax

$.ajax({
  url: url,
  dataType: 'script',
  success: success
});

$.isArray(obj)#Defined in: kimbo.js:1878

Determine if the parameter passed is an array object.

Parameters

obj
object
Object to test if its an array.

Returns boolean According wether or not it is an array object.

Usage

$.isArray([]); // True
$.isArray({}); // False
$.isArray('test'); // False

$.isBoolean(obj)#Defined in: kimbo.js:2171

Determine if the parameter passed is boolean.

Parameters

obj
object
Object to test if its boolean..

Returns boolean According wether or not it is boolean.

Usage

$.isBoolean(false); // True
$.isBoolean(3); // False

$.isEmptyObject(obj)#Defined in: kimbo.js:1922

Determine if the parameter passed is an empty object.

Parameters

obj
object
Object to test if its an empty object.

Returns boolean According wether or not it is an empty object.

Usage

$.isEmptyObject({}); // True
$.isEmptyObject([]); // True
$.isEmptyObject([1, 2]); // False

$.isFunction(obj)#Defined in: kimbo.js:2125

Determine if the parameter passed is a Javascript function object.

Parameters

obj
object
Object to test if its a function.

Returns boolean According wether or not it is a function.

Usage

var myFunction = function () {};
$.isFunction(myFunction); // True
var something = ['lala', 'jojo'];
$.isFunction(something); // False

$.isMobile()#Defined in: kimbo.js:1943

Determine if the current platform is a mobile device, (otherwise is a desktop browser).

Parameters

Returns boolean According wether or not is a mobile device.

Usage

$.isMobile(); // False

$.isNumeric(obj)#Defined in: kimbo.js:1891

Determine if the parameter passed is an number.

Parameters

obj
object
Object to test if its a number.

Returns boolean According wether or not it is a number.

Usage

$.isNumeric(3); // True
$.isNumeric('3'); // False

$.isObject(obj)#Defined in: kimbo.js:2141

Determine if the parameter passed is a Javascript plain object.

Parameters

obj
object
Object to test if its a plain object.

Returns boolean According wether or not it is a plain object.

Usage

$.isObject({}); // True
$.isObject([]); // False
$.isObject('test'); // False

$.isString(obj)#Defined in: kimbo.js:2156

Determine if the parameter passed is a string.

Parameters

obj
object
Object to test if its a string.

Returns boolean According wether or not it is a string.

Usage

$.isString('test'); // True
$.isString({ name: 'asd' }); // False

$.isWindow(obj)#Defined in: kimbo.js:1906

Determine if the parameter passed is the window object.

Parameters

obj
object
Object to test if its the window object.

Returns boolean According wether or not it is the window object.

Usage

$.isWindow(window); // True
$.isWindow({ window: window }); // False

$.makeArray(obj)#Defined in: kimbo.js:2053

Create an Array from the given object

Parameters

obj
array object
The Array or Object to make an array from.

Returns array A new array.

Usage

var lis = $('li'); // Kimbo object
var arr = $.makeArray(lis);

console.log($.isArray(lis)); // False
console.log($.isArray(arr)); // True

$.map(obj)#Defined in: kimbo.js:2022

Translate all items in an array or object to new array of items.

Parameters

obj
array object
The Array or Object to translate.

Returns array A new array.

Usage

var arr = ['a', 'b', 'c'];
arr = $.map(arr, function (element, index) {
  return element.toUpperCase() + index;
});
console.log(arr); // ['A0', 'B1', 'C2']

Or wit an object

var obj = {a: 'a', b: 'b', c: 'c'};
obj = $.map(arr, function (key, value) {
  return key + ': ' + value.toUpperCase();
});
console.log(obj); // ['a: A', 'b: B', 'c: C']

$.merge(first, second)#Defined in: kimbo.js:2080

Merge the contents of two arrays into the first array passed.

Parameters

first
array
The first array to merge the contents of the second.
second
array string
The second array to merge into the first.

Returns array The first array merged with the second.

Usage

$.merge(['a', 'b'], ['c', 'd']);

Result:

['a', 'b', 'c', 'd']

$.param(data)#Defined in: kimbo.js:3221

Create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

Parameters

data
string object
A string or object to serialize.

Usage

var obj = { name: 'Denis', last: 'Ciccale' };
var serialized = $.param(obj); // 'name=Denis&last=Ciccale'

$.parseJSON(data)#Defined in: kimbo.js:1964

Parses a well-formed JSON string and returns the resulting JavaScript object.

Parameters

data
string
The JSON string to parse.

Returns object A JavaScript object.

Usage

var obj = $.parseJSON('{"name":"Denis"}');
console.log(obj.name === 'Denis'); // True

$.parseXML(data)#Defined in: kimbo.js:1984

Parses a string into an XML document.

Parameters

data
string
The JSON string to parse.

Returns object A JavaScript object.

Usage

var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>"
var xmlDoc = $.parseXML(xml);
$(xmlDoc).find('title'); // 'RSS Title'

$.post(url, [data], callback, [type])#Defined in: kimbo.js:3086

Load data from the server using HTTP POST request.

Parameters

url
string
A string containing the URL to which the request is sent.
data
string object optional
An option string or object with data params to send to the server.
callback
function
A callback function to execute if the request succeeds.
type
string optional
String with the type of the data to send (intelligent guess by default).

Usage

$.post('url/users.php', { user: 'denis', pass: '123' }, function (data) {
  // Success
  console.log('response:', data);
});

This method is a shorthand for the $.ajax

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

$.typeOf(obj)#Defined in: kimbo.js:1853

Determine the internal JavaScript [[Class]] of an object.

Parameters

obj
object
Object to get its [[Class]] type.

Returns string Type of the object.

Usage

$.typeOf('i am a string'); // 'string'
$.typeOf(/(\.regexp?)/); // 'regexp'
$.typeOf(null); // 'null'
$.typeOf(undefined); // 'undefined'
$.typeOf(window.notDefined); // 'undefined'
$.typeOf(function () {}); // 'function'
$.typeOf({key: 'value'}); // 'object'
$.typeOf(true); // 'boolean'
$.typeOf([]); // 'array'
$.typeOf(new Date()); // 'date'
$.typeOf(3); // 'number'

$(…)#Defined in: kimbo.js:42

Kimbo object collection.All methods called from a Kimbo collection affects all elements in it.

$(…).add(selector, [context])#Defined in: kimbo.js:1615

Add elements to the current Kimbo collection.

Parameters

selector
string object
Selector of the element or the actual DOM or Kimbo object.
context
string object optional
Selector of the context element or the actual DOM or Kimbo object.

Returns object The merged Kimbo collection.

Usage

<ul id="menu1">
  <li>Apple</li>
  <li>Orange</li>
</ul>

<ul id="menu2">
  <li>Lemon</li>
  <li>Banana</li>
</ul>

Get the items from the #menu1 and add the ones from #menu2, all the following ways will produce the same collection

$('#menu1 li').add('#menu2 li');

or

$('#menu1 li').add('li', '#menu2');

or

$('#menu1 li').add($('#menu2 li'));

$(…).addClass(name)#Defined in: kimbo.js:801

Adds a class to all matched elements.

Parameters

name
string
Name of the class to add.

Returns object Original matched collection.

Usage

<p>I want to be green</p>
<script>
$('p').addClass('green');
</script>

Now it's green

<p class="green">I want to be green</p>

You can add multiple classes separated by a space

<p>Add classes to me</p>
<script>
$('p').addClass('green big width100');
</script>

All classes added and they won't be repetead if you try to add an existing one

<p class="green big width100">Add classes to me</p>

$(…).append(value)#Defined in: kimbo.js:886

Insert content to the end of all elements matched by Kimbo.

Parameters

value
string object
HTML string, DOM element, or Kimbo object to insert.

Returns object Original matched collection.

Usage

<div class="container">
  <p class="lorem">Lorem </p>
  <p class="lorem">Lorem </p>
</div>

Insert content

$('.lorem').append('<em>ipsum</em>')

Each element gets the content

<div class="container">
  <p class="lorem">Lorem <em>ipsum</em></p>
  <p class="lorem">Lorem <em>ipsum</em></p>
</div>

You can also get an element and insert it elsewhere

$('.container').append($('.ipsum'))

The selected element will be moved, not cloned.

<div class="container">
  <p class="lorem">Lorem</p>
  <p class="lorem">Lorem</p>
  <p class="ipsum">Ipsum</p>
</div>

$(…).attr(name, [value])#Defined in: kimbo.js:1021

Get an attribute value from one element or set attributes to all matched elements.

Parameters

name
string
Name of the attribute.
value
string optional
Value for the attribute.

Returns string Attribute value, only if name was passed.

Returns object Original matched collection when setting a value.

Usage

<a href="http://kimbojs.com">Go to Kimbojs.com</a>

Get href attribute

$('a').attr('href'); // Http://kimbojs.com

Set a new attribute

$('a').attr('title', 'Go to Kimbojs.com');

Now element has a title attribute

<a href="http://kimbojs.com" title="Go to Kimbojs.com">Go to Kimbojs.com</a>

$(…).children([selector])#Defined in: kimbo.js:1757

Get the children of all matched elements, optionally filtered by a selector.

selector
string optional
A string selector to match elements against.

Returns object Kimbo object

Usage

Suppose a page with the following HTML:

<div class="demo">
  <p>This</p>
  <p>is</p>
  <p>a</p>
  <p>demo.</p>
</div>

Get all children of .demo:

$('.demo').children(); // Al <p> tags inside .demo div

Another example passing an specific selector:

<form>
  <input type="text" name="name" />
  <input type="text" name="last" />
  <input type="submit" value="Send" />
</form>

Get only the children that are text type elements:

$('form').children('input[type="text"]'); // Only name and last inputs

$(…).clone()#Defined in: kimbo.js:1142

Clones a DOM node.

Parameters

Returns object Original matched collection.

Usage

<p class="asd foo qwe">Lorem ipsum.</p>
var p1 = $('p'); // Grab the p element
var p2 = p1.clone(); // Clone p1 into p2
console.log(p2 === p1); // False

$(…).closest(selector, [context])#Defined in: kimbo.js:1530

Get a Kimbo collection that matches the closest selector

Parameters

selector
string
A string selector to match elements.
context
string optional
A DOM element within which matching elements may be found.

Returns object Kimbo object

Usage

Here we have a nested unordered lists:

<ul>
  <li>
    Item 1
    <ul class="ul-level-2">
      <li class="item-1-1">Item 1.1</li>
      <li class="item-1-2">Item 1.2</li>
    </ul>
  </li>
  <li>Item 2</li>
</ul>

You can find the containing ul of the items in the nested ul:

$('.item-1-1').closest('ul');

This will return ul.level-2 element

$(…).contains(element)#Defined in: kimbo.js:1583

Determine whether an element is contained by the current matched element.

Parameters

element
string object
Selector of the element or the actual DOM or Kimbo object.

Returns boolean true if it is contained, false if not.

Usage

<div id="container">
  <p id="inside">Inside paragraph</p>
</div>
<p id="outside">Outside paragraph</p>

The paragraph with id "inside" is actually contained by "#container"

$('#container').contains('#inside'); // True

The paragraph ourside is not contained

var outside_p = $('#outside');
$('#container').contains(outside_p); // False

$(…).contents()#Defined in: kimbo.js:1772

Get the HTML content of an iframe

Returns object Kimbo object

Usage

Suppose an iframe loading an external page:

<iframe src="http://api.kimbojs.com"></iframe>

Find the body element of the contents of that iframe:

$('iframe').contents().find('body');

$(…).css(property, [value])#Defined in: kimbo.js:643

Get the css value of a property from one element or set a css property to all matched elements.

Parameters

property
string object
Name of the css property.
value
string number optional
Value for the property.

Returns object Original matched collection.

Usage

<p>Hello dude!</p>

Modify some styles

$('p').css('color', 'red'); // Now the text is red

The HTML will look like this:

<p style="color: red;">Hello dude!</p>

You can also pass an object for setting multiple properties at the same time

$('p').css({
  color: 'red',
  'font-size': '30px',
  backgroundColor: 'blue'
});

Properties can be dash-separated (add quotes) or camelCase.

<p style="color: red; font-size: 30px; background-color: blue">Hello dude!</p>

$(…).data(key, [value])#Defined in: kimbo.js:445

Store or retrieve elements dataset.

Parameters

key
string
Key of the data attribute to to set.
value
string optional
Value to store in dataset.

Returns object Original matched collection.

Usage

<div id="panel"></div>

Set some data to the panel:

$('#panel').data('isOpen', true);

No a data-* attribute was added

<div id="panel" data-isOpen="true"></div>

We can retrieve the data

$('#panel').data('isOpen'); // 'true'

$(…).each(callback)#Defined in: kimbo.js:1423

Iterate over a Kimbo objct, executing a function for each element.

Parameters

callback
function
A function to call for each element in the collection.

Returns object Kimbo object

Usage

Here we have an unordered list:

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ul>

You can iterate over all the list items and execute a function

$('li').each(function (el, index, collection) {
  console.log('index of ' + $(this).text() + ' is: ' + index);
});

This will log the following message

index of Item 1 is: 0

index of Item 2 is: 1

index of Item 3 is: 2

$(…).empty()#Defined in: kimbo.js:968

Remove all child nodes from the DOM of the elements in the collection.

Returns object Original matched collection.

Usage

<div class="container">
  <p class="lorem">Lorem</p>
  <p class="lorem">Lorem</p>
</div>

Empty .container

$('.container').empty();

All elements inside ".container" are removed from the DOM

<div class="container"></div>

$(…).eq(index)#Defined in: kimbo.js:1329

Reduce the matched elements collection to the one at the specified index.

Parameters

index
number
An integer indicating the position of the element. Use a negative number to go backwards in the collection.

Returns object Kimbo object at specified index.

Usage

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
</ul>

Get 3rd element, index always start at 0, so to get the 3rd we need to pass the number 2.

$('li').eq(2); // Item 3

$(…).filter(selector)#Defined in: kimbo.js:1289

Filter element collection by the passed argument.

Parameters

selector
string object function
The argument by which the collection will be filtered.

Returns object Filtered elements collection.

Usage

<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
</ul>

Get even items.

$('li').filter(':nth-child(even)').addClass('even');

Only even items were affected.

<ul>
  <li>One</li>
  <li class="even">Two</li>
  <li>Three</li>
  <li class="even">Four</li>
</ul>

Using a function(index, element)

You can also filter the collection using a function, receiving the current index and element in the collection.

$('li').filter(function (index, element) {
  return index % 3 == 2;
}).addClass('red');

This will add a 'red' class to the third, sixth, ninth elements and so on...

Filter by DOM or Kimbo object

You can also filter by a DOM or Kimbo object.

$('li').filter(document.getElementById('id'));
// Or a Kimbo object
$('li').filter($('#id'));

$(…).find(selector)#Defined in: kimbo.js:1473

Find descendant elements for each element in the current collection.

Parameters

selector
string
A string selector to match elements.

Returns object Kimbo object

Usage

Here we have some HTML

<div id="container">
  <p>Demo</p>
  <div class="article">
    <p>This is an article</p>
    <p>with some paragraphs</p>
  </div>
</div>

You can find all paragraph elements inside the article:

$('.article').find('p');

$(…).first()#Defined in: kimbo.js:1347

Reduce the matched elements collection to the first in the set.

Returns object First Kimbo object of the collection

Usage

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ul>

Get only the first element

$('li').first(); // Item 1

$(…).get([index])#Defined in: kimbo.js:184

Retrieve native DOM elements from the current collection

Parameters

index
number optional
A zero-based integer indicating which element to retrieve, supports going backwards with negative index.

Returns array object An array of the native DOM elements or the specified element by index matched by Kimbo.

Usage

<ul>
  <li id="foo"></li>
  <li id="bar"></li>
</ul>

Get standard array of elements

$('li').get(); // [<li id="foo">, <li id="bar">]

Get the first element

$('li').get(0); // <li id="foo">

Get the last element

$('li').get(-1); // <li id="bar">

$(…).hasClass(name)#Defined in: kimbo.js:1105

Determine whether any matched elements has the given class.

Parameters

name
string
Name of the class to search for.

Returns object Original matched collection.

Usage

<p class="asd foo qwe">Lorem ipsum.</p>

Check if the element has the class 'foo'

$('p').hasClass('foo'); // True

You could also check if it has multiple classes

$('p').hasClass('qwe asd'); // True

$(…).height([value])#Defined in: kimbo.js:1191

Get the current height of the first element or set the height of all matched elements.

Parameters

value
number string optional
An integer indicating the height of the element or a string height a unit of measure.

Returns number the actual height of the element if no parameter passed.

Returns object Kimbo object.

Usage

<style>
  div { height: 100px; }
</style>
<div>Actual height is 100px</div>

Get the height:

$('div').height(); // 100

Change the height:

$('div').height(200); // Now its height is 200

Or passing a specific unit:

$('div').height('50%'); // Now its height is 50%

$(…).hide()#Defined in: kimbo.js:601

Hide all matched elements.

Returns object Original matched collection.

Usage

<p>Lorem</p>

Hide it

$('p').hide();

Now it's hidden

<p style="display: none;">Lorem</p>

$(…).hover(fnOver, [fnOut])#Defined in: kimbo.js:2768

A shortcut method to register moseenter and/or mouseleave event handlers to the matched elements.

Parameters

fnOver
function
A function to execute when the cursor enters the element.
fnOut
function optional
A function to execute when the cursor leaves the element.

Usage

Suppose a div element:

<div id='box'></div>

Register hover event

var fnOver = function () { console.log('enter'); };
var fnOut = function () { console.log('leave'); };

$('.box').hover(fnOver, fnOut);

When the cursor enters the .box element the console will log:

'enter'

When the cursor leaves the .box element the console will log:

'leave'

$(…).html([value])#Defined in: kimbo.js:735

Get the HTML content of the first element in the set or set the HTML content of all the matched elements.

Parameters

value
string optional
A string of HTML to set as the HTML content of all matched elements.

Returns string a string value of the HTML content of the element if no parameter passed.

Returns object current Kimbo object.

Usage

Get the HTML content of an element

<p><span>Demo text<span></p>

without passing any parameter to the function:

$('p').html(); // '<span>Demo tetxt</span>'

To replace the HTML content of the paragraph pass a string parameter to the function:

$('p').html('<strong>Another content</strong>');

Now the text content was replaced:

<p><strong>Another content</strong></p>

$(…).is(selector)#Defined in: kimbo.js:1644

Check the current elements collection against a selector, object or function.

selector
string object function
The argument by which the collection will be matched against.

Returns boolean  

Usage

<ul>
  <li>Click the <em>Apple</em></li>
  <li><span>Click the Orange</span></li>
  <li>Or the Banana</li>
</ul>

Test if the current clicked element is an <li> element.

$('ul').click(function (event) {
  var $target = $(event.target);
  if ($target.is('li')) {
    $target.css('background-color', 'red');
  }
});

$(…).last()#Defined in: kimbo.js:1365

Reduce the matched elements collection to the last in the set.

Returns object Last Kimbo object of the collection

Usage

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ul>

Get only the last element

$('li').last(); // Item 3

$(…).length#Defined in: kimbo.js:119

The length of the current Kimbo collection.

Returns number Integer representing the lenght of the current collection.

Usage

Having these paragraphs:

<p>one</p>
<p>two</p>
<p>three</p>

Grab them and check for the length property:

$('p').length; // 3

$(…).map(callback)#Defined in: kimbo.js:1448

Execute a function for each element in the collection, producing a new Kimbo set with the returned values

Parameters

callback
function
A function to call for each element in the collection.

Returns object Kimbo object

Usage

Here we have an unordered list:

<ul>
  <li id="item1">Item 1</li>
  <li id="item2">Item 2</li>
  <li id="item3">Item 3</li>
</ul>

You can call a function for each element to create a new Kimbo object

$('li').map(function (el, index) {
  return this.id;
}).get().join();

This will produce a list of the item ids.

"item1,item2,item3"

$(…).next([selector])#Defined in: kimbo.js:1688

Get the immedeately following sibling of each element in the current collection.If a selector is specified, it will return the element only if it matches that selector.

selector
string optional
A string containing a selector expression to match elements against

Returns object Kimbo object

Usage

Suppose a page with this HTML:

<ul>
  <li class="item-a">Item 1</li>
  <li class="item-b">Item 2</li>
</ul>

Get the parent element of .item-a

$('.item-a').next(); // .item-b

$(…).off([type], [selector], [callback])#Defined in: kimbo.js:2700

Remove an event handler to the selected elements for the specified type, or all of them if no type defined.

Parameters

type
string optional
A string name for the event to remove, or All if none specified.
selector
string optional
A string selector to undelegate an event from that element.
callback
function optional
A specific callback function if there are multiple registered under the same event type

Usage

Suppose a button element:

<button id='btn'>click me</button>

Register a click event handler

$('#btn').on('click', function (event) {
  console.log('clicked!', event);
});

Remove the handler

$('#btn').off('click');

Also you could specify the handler for example:

var firstFunction = function () { console.log('first fn'); };
var secondFunction = function () { console.log('second fn'); };
var btn = $('#btn');
btn.click(firstFunction);
btn.click(secondFunction);

If you want to remove the click event only for the second function, do this:

btn.off('click', secondFunction);

Or if you want to remove All handlers (click and any other attached):

btn.off();

$(…).on(type, [selector], [data], callback)#Defined in: kimbo.js:2637

Add an event handler to the selected elements.

Parameters

type
string
A string name for the event to register.
selector
string optional
Delegate an event providing a string selector.
data
any optional
Data to be passed to the handler in event.data when an event is triggered.
callback
function
A callback function to execute when the event is triggered.

Usage

Suppose a button element:

<button id='btn'>click me</button>

Register a click event handler

$('#btn').on('click', function (event) {
  console.log('clicked!', event);
});

There are shorthands for all events for example:

$('#btn').click(function (event) {
  console.log('clicked!', event);
});

Passing some data when registering the handler:

$('#btn').on('click', { name: 'denis' }, function (event) {
  // Data passed is inside event.data
  console.log('name:', event.data.name);
});

Here is a list for all the shorthand methods available:

'blur', 'change', 'click', 'contextmenu', 'dblclick', 'error',
'focus', 'keydown', 'keypress', 'keyup', 'load', 'mousedown', 'mouseenter', 'mouseleave',
'mousemove', 'mouseout', 'mouseup', 'mouseover', 'resize', 'scroll', 'select', 'submit', 'unload'

$(…).parent([selector])#Defined in: kimbo.js:1666

Get the parent of each element matched in the current collection.If a selector is specified, it will return the parent element only if it matches that selector.

selector
string optional
A string containing a selector expression to match elements against

Returns object Kimbo object

Usage

Suppose a page with this HTML:

<ul>
  <li class="item-a">Item 1</li>
  <li class="item-b">Item 2</li>
</ul>

Get the parent element of .item-a

$('.item-a').parent(); // Ul

$(…).prepend(value)#Defined in: kimbo.js:915

Insert content to the beginning of all elements matched by Kimbo.

Parameters

value
string object
HTML string, DOM element, or Kimbo object to insert.

Returns object Original matched collection.

Usage

<div class="container">
  <p class="lorem"> Lorem</p>
  <p class="lorem"> Lorem</p>
</div>

Insert content

$('.lorem').prepend('<em>ipsum</em>')

Each element gets the content

<div class="container">
  <p class="lorem"><em>ipsum</em> Lorem</p>
  <p class="lorem"><em>ipsum</em> Lorem</p>
</div>

You can also get an element and insert it elsewhere

$('.container').prepend($('.ipsum'))

The selected element will be moved, not cloned.

<div class="container">
  <p class="ipsum">Ipsum</p>
  <p class="lorem">Lorem</p>
  <p class="lorem">Lorem</p>
</div>

$(…).prev([selector])#Defined in: kimbo.js:1708

Get the immedeately previous sibling of each element in the current collection.If a selector is specified, it will return the element only if it matches that selector.

selector
string optional
A string containing a selector expression to match elements against

Returns object Kimbo object

Usage

Suppose a page with this HTML:

<ul>
  <li class="item-a">Item 1</li>
  <li class="item-b">Item 2</li>
</ul>

Get the parent element of .item-a

$('.item-b').prev(); // .item-a

$(…).ready(callback)#Defined in: kimbo.js:137

Execute a callback after de DOM is completely loaded

Parameters

callback
function
A function to call after de DOM is ready

Returns object The original element

Usage

$(document).ready(function () {
  console.log('the DOM is loaded!');
});

Or using the shortcut (recommended)

$(function () {
  console.log('the DOM is loaded!);
});

$(…).remove()#Defined in: kimbo.js:994

Remove all matched elements from the DOM.Similar to $(…).empty but .remove() removes the element itself

Returns object Original matched collection.

Usage

<div class="container">
  <p class="lorem">Lorem</p>
  <p>Lorem</p>
</div>

Remove one element

$('.lorem').remove();

The result element is:

<div class="container">
  <p>Lorem</p>
</div>

$(…).removeAttr(name)#Defined in: kimbo.js:1049

Removes an attribute from all matched elements.

Parameters

name
string
Name of the attribute to remove.

Returns object Original matched collection.

Usage

<a href="http://kimbojs.com" title="Go to Kimbojs.com">Go to Kimbojs.com</a>

Remove the title attribute

$('a').removeAttr('title');

Now the element has no title

<a href="http://kimbojs.com">Go to Kimbojs.com</a>

$(…).removeClass(name)#Defined in: kimbo.js:824

Removes a class to all matched elements.

Parameters

name
string
Name of the class to remove.

Returns object Original matched collection.

Usage

<p class="big green title float-rigth">Lorem ipsum</p>

Remove a specific class from the paragraph:

$('p').removeClass('green');

The specified class was removed:

<p class="big title float-right">Lorem ipsum</p>

You can remove multiple classes separating them by a space when calling the function:

$('p').removeClass('big title');

Now only one class left:

<p class="float-right">Lorem ipsum</p>

You can remove all classes just calling .removeClass() without parameters

$('p').removeClass();

All classes were removed including the class attribute:

<p>Lorem ipsum</p>

$(…).removeData(key)#Defined in: kimbo.js:480

Remove data from the element dataset.

Parameters

key
string
Key of the data attribute to to remove.

Returns object Original matched collection.

Usage

<div id="panel" data-isOpen="true"></div>

Remove data associated to the panel div:

$('#panel').removeData('isOpen');

Data attribute and value was removed:

<div id="panel"></div>

data-isOpen is undefined

$('#panel').data('isOpen'); // Undefined

$(…).show()#Defined in: kimbo.js:559

Display all matched elements.

Returns object Original matched collection.

Usage

<p style="display: none;">Lorem</p>

Show it

$('p').show();

Now it's visible

<p style="display: block;">Lorem</p>

$(…).sibling([selector])#Defined in: kimbo.js:1728

Get the immedeately previous sibling of each element in the current collection.If a selector is specified, it will return the element only if it matches that selector.

selector
string optional
A string containing a selector expression to match elements against

Returns object Kimbo object

Usage

Suppose a page with this HTML:

<ul>
  <li class="item-a">Item 1</li>
  <li class="item-b">Item 2</li>
</ul>

Get the parent element of .item-a

$('.item-b').prev(); // .item-a

$(…).slice(start, [end])#Defined in: kimbo.js:1393

Reduce the matched elements collection to a subset specified by a range of indices

Parameters

start
number
An integer indicating the position at which the elements begin to be selected. Use a negative number to go backwards in the collection.
end
number optional
An integer indicating the position at which the elements stop being selected. Use a negative number to start at the end of the collection. If ommited, the range continues to the end.

Returns object Reduced Kimbo object collection in the range specified

Usage

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
  <li>Item 5</li>
</ul>

This will add the class selected to Item 3, 4 and 5, as the index starts at 0

$('li').slice(2).addClass('selected');

This will select only Items 3 and 4

$('li').slice(2, 4).addClass('selected');

Negative index

Here only Item 4 will be selected since is the only between -2 (Item 3) and -1 (Item 5)

$('li').slice(-2, -1).addClass('selected');

$(…).text([value])#Defined in: kimbo.js:716

Get the text of the first element in the set or set the text of all the matched elements.

Parameters

value
string optional
A string of text to set as the text content of all matched elements.

Returns string string value of the text content of the element if no parameter passed.

Returns object current Kimbo object.

Usage

Get the text content of an element

<p>Demo text</p>

without passing any parameter to the function:

$('p').text(); // 'Demo text'

To replace the text of the paragraph pass a string parameter to the function:

$('p').text('Another text');

Now the text content was replaced:

<p>Another text</p>

$(…).toggleClass(name, [state])#Defined in: kimbo.js:1071

Removes a class to all matched elements.

Parameters

name
string
Name of the class to toggle.
state
boolean optional
If state is true the class will be added, if false, removed.

Returns object Original matched collection.

Usage

<p class="foo">Lorem ipsum.</p>
<script>
$('p').toggleClass('foo');
</script>

The p element has the class foo soo it will be removed

<p>Lorem ipsum.</p>

$(…).trigger([type], [data])#Defined in: kimbo.js:2742

Execute all handlers attached to the matched elements for the fiven event type.

Parameters

type
string optional
A string name for the event to remove, or All if none specified.
data
any optional
Additional parameters to be passed to the handler in event.data when an event is triggered.

Usage

Suppose a button element:

<button id='btn'>click me</button>

Register a click event handler

$('#btn').on('click', function (event, data) {
  console.log('name', data.name);
});

Trigger the event programatically passing some data:

$('#btn').trigger('click', { name: 'denis' });
// 'name denis'

Allow the handler to recieve multiple data:

$('#btn').on('click', function (event, name, last) {
  console.log('name', name);
  console.log('last', last);
});
$('#btn').trigger('click', ['denis', 'ciccale']);
// Name denis
// Last ciccale

$(…).val([value])#Defined in: kimbo.js:754

Get the current value of the first element in the set or set the value of all the matched elements.

Parameters

value
string optional
A string of text to set as the value of all matched elements.

Returns string the current value of the first element if no parameter passed

Returns object current Kimbo object

Usage

Get the value of a form element:

<input type="text" name="color" value="red" />

without passing any parameter to the function:

$('input').val(); // 'red'

To change the value of the input pass a string parameter to the function:

$('input').val('blue');

Now the value was changed:

$('input').val(); // 'blue'

$(…).width([value])#Defined in: kimbo.js:1170

Get the current width of the first element or set the width of all matched elements.

Parameters

value
number string optional
An integer indicating the width of the element or a string width a unit of measure.

Returns number the actual width of the element if no parameter passed.

Returns object Kimbo object.

Usage

<style>
  div { width: 100px; }
</style>
<div>Actual width is 100px</div>

Get the width:

$('div').width(); // 100

Change the width:

$('div').width(200); // Now its width is 200

Or passing a specific unit:

$('div').width('50%'); // Now its width is 50%
×