Did you find this useful?
Socialize it today.

jQuery One Event

Monday, July 02, 2012

The jQuery one event is used to attach one or more event handlers for selected elements. It also specifies a function to run when the event is triggered. When using the one method, the event handler is only triggered once per attached element.



eventOne or more events to attach. Event values are separated by space
dataAdditional optional data to pass along to the function
functionOptional function to run when the event(s) occur


In the following jQuery example, the one() method adds the click event to the element with an id of "imgMouse". When the "imgMouse" element is clicked, the "click" event is executed through the one method. In this example, the div text is altered and the font-size is changed as the mouse icon is clicked. Try it yourself, by clicking the mouse icon.

<div id="divParent">
    <img id="imgMouse"src="#" />
    <div id="divChild">
    <div id="divText">Click the mouse icon ....

$("#imgMouse").one("click", function () {
    $("#divChild").css("font-size", "2.5em");
    $("#divChild").text("Thanks for clicking me!");

Click the mouse icon so I can grow in size!

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.

Recommended Books & Training Resources

JavaScript and jQuery: The Missing Manual Pro jQuery HTML CSS and JavaScript Editor