Home >>jQuery Tutorial >jQuery one() Method

jQuery one() Method

jQuery one() Method

jQuery one() method in jQuery is used to add one or multiple event handlers for the selected elements, and specifies a function to run when the event occurs.

Syntax:
$(selector).one(event,data,function)

Parameter Values

Parameter Description
event It is a required parameter and used to specifies one or multiple events to add to the elements.
data It is an optional parameter and used to specifies additional data to pass along to the function
function It is a required parameter and used to specifies the function to run when the event occurs
Here is an example of jQuery one() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt").one("click", function(){
$(this).animate({fontSize: "+=4px"});
});
});
</script>
</head>
<body>
<p class="txt">This is First paragraph.</p>
<p class="txt">This is Second paragraph.</p>
<p class="txt">Click any p element to increase its text size.</p>
</body>
</html>

Output:

This is First paragraph.

This is Second paragraph.

Click any p element to increase its text size.


No Sidebar ads