Back

Selectors

ID

Match the element with id="foo"

$('#foo')

Class

Match all elements with class="foo"

$('.foo')

Tag

Match all elements with a given tag name

$('p')

CSS Selectors

DollarJS matches most CSS Selectors with a few Limitations

$('p.foo')
$('p span')
$('p > span')
$('li:first-child')
$('h2[foo="bar"]')
$('input:checked')
$('#multiple, .multiple')

Element

Wrap the provided Element in DollarJS

$(document.getElementById('foo'))

Array of Elements

Wrap the provided elements in DollarJS

$([document.getElementById('foo'), document.getElementById('bar')])

Window

Wrap the window object in DollarJS

$(window)

Node

Wrap the provided node in DollarJS

$(document)

NodeList

Wrap the provided NodeList in DollarJS

$(document.body.childNodes)

HTMLString

Create new DOM Elements from a string of HTML markup and return a DollarJS instance that contains them

$('<div class="created"><p></p></div>')

DollarJS

Takes a DollarJS instance and uses the selected elements from that instance

$($('p'))

Function

Invoke the provided function as soon as DOM is ready to be accessed (or immediately if this has already happened)

$(function(){
    // do stuff
})

Ignored

Matches no elements

$(undefined)
$('')
$(null)
$(false)
$(true)
$(456)
$([1,2,3])
$({ abc: 123 })