$()
$(selector, [context]) ⇒ collection
$(<Zepto collection>) ⇒ same collection
$(<DOM nodes>) ⇒ collection
$(htmlString) ⇒ collection
$(htmlString, attributes) ⇒ collection [v1.0]
Zepto(function($){ ... })
Create a Zepto collection object by performing a CSS selector, wrapping DOM nodes, or creating elements from an HTML string.
A Zepto collection is an array-like object that has chainable methods for
manipulating the DOM nodes it references. All of the methods in this documentation
are collection methods, except the ones directly on the dollar (Zepto
) object,
such as $.extend
.
If a context (CSS selector, DOM node or Zepto collection object) is
given, perform the CSS selector only within nodes of the context; this is
functionally the same as calling $(context).find(selector)
.
When an HTML string is given, use it to create DOM nodes. If an attributes map
is given via argument, apply them to all created elements. For fast single
element creation, use <div>
or <div/>
forms.
When a function is given, attach it as a handler for the DOMContentLoaded
event.
If the page is already loaded, executes the function immediately.
$('div') //=> all DIV elements on the page
$('#foo') //=> element with ID "foo"
// create element:
$("<p>Hello</p>") //=> the new P element
// create element with attributes:
$("<p />", { text:"Hello", id:"greeting", css:{color:'darkblue'} })
//=> <p id=greeting style="color:darkblue">Hello</p>
// execute callback when the page is ready:
Zepto(function($){
alert('Ready to Zepto!')
})
[jQuery CSS extensions][ext] are not supported. However, the optional "selector" module provides limited support for a few of the most used pseudo-selectors, and can be dropped in for compatibility with existing code or plugins.
Zepto will only set the `$` global to itself if it is not yet defined. This allows you to use Zepto with legacy code that uses, for example, Prototype.js. Just load Prototype first, and Zepto will not touch Prototype's `$` function. Zepto will always set the `Zepto` global to itself.