one() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:one

Description

The one() method attaches handlers which is only run ONCE for each element.

Syntax

$(selector).one(event,data,function);
Parameter RequireDescription
event Required. one or more events to attach to the elements. Multiple event values are separated by space. Must be a valid event.
data Optional. additional data to pass along to the function
function Required. the function to run when the event occurs

The following code shows how to Increase the text size of a <p> element once when it is clicked:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").one("click dblclick", function(){
        $(this).animate({fontSize: "+=6px"});
    });/*from   w  w w . j ava  2 s.  c  om*/
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>

Related Tutorials