Sunday, October 2, 2011

one()

one(String type, Object data, Function fn) returns jQuery

Binds a handler to a particular event (like click) for each matched element. The handler is executed only once for each element. Otherwise, the same rules as described in bind() apply. The
event handler is passed an event object that you can use to prevent default behaviour. To stop both default action and event bubbling, your handler has to return false.
In most cases, you can define your event handlers as anonymous functions (see first example). In cases where that is not possible, you can pass additional data as the second paramter (and the handler function as the third), see second example.

Example:


$("p").one("click", function(){
alert( $(this).text() );
});

HTML:
<p>Hello</p>

Result:
alert("Hello")

No comments:

Post a Comment