Introduction
Today we will learn how to fire an event only once in jQuery. This is a simple demo of the jQuery one() function. I hope you will like it.
Please see to this article in my blog.
Background
While I was doing some tasks, I wanted to make a click event that is to be fired only once for a user when the user is logged in. I used the jQuery one function to do it, so I thought of sharing it with you all.
Using the code
As you all know we can handle many events in the client side using jQuery. Here I am sharing with you one of those events that will definitely help you one day in your application.
To start with loading the jQuery reference, I will use the Google CDN here:
- <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
- <p>Click Me</p>
- p {
- color: red;
- width: auto;
- height: 50px;
- margin: 250px;
- border: 1px solid #ccc;
- padding: 25px;
- text-align: center;
- }
- <script>
- $(document).ready(function(){
- $("p").one( "click", function() {
- $(this ).text("You clicked me!. Now you can't do anything!!!!");
- });
- });
- </script>
Complete Code
- <html>
- <head>
- <title>JQuery one demo - Sibeesh Passion</title>
- <style>
- p {
- color: red;
- width: auto;
- height: 50px;
- margin: 250px;
- border: 1px solid #ccc;
- padding: 25px;
- text-align: center;
- }
- </style>
- <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
- </head>
- <body>
- <p>Click Me</p>
- <script>
- $(document).ready(function(){
- $("p").one( "click", function() {
- $(this ).text("You clicked me!. Now you can't do anything!!!!");
- });
- });
- </script>
- </body>
- </html>
I hope you will like this article. Please share with me your valuable thoughts and comments. Your feedback is always welcome.
Thanks in advance. Happy coding!

Sibeesh VenuPosted Jun 29, 2015, 3:26 AM
VD tripathi Thank you
Vishwakant TripathiPosted Jun 28, 2015, 3:19 AM
Nice
Sibeesh VenuPosted Jun 23, 2015, 11:32 AM
Vipul Malhotra Thank you :)
Sibeesh VenuPosted Jun 23, 2015, 11:32 AM
Shailesh Uke Thank you :)
Sibeesh VenuPosted Jun 23, 2015, 11:32 AM
Jaipal Reddy Thank you :)
Vipul MalhotraPosted Jun 23, 2015, 10:34 AM
Great
Shailesh UkePosted Jun 23, 2015, 10:23 AM
Nice Article............
Jaipal ReddyPosted Jun 23, 2015, 5:25 AM
good one Sibeesh
Sibeesh VenuPosted Jun 23, 2015, 5:15 AM
Upendra Pratap Shahi Thanks buddy.
Upendra Pratap ShahiPosted Jun 23, 2015, 4:48 AM
good one Sibeesh Venu
Sibeesh VenuPosted Jun 23, 2015, 1:59 AM
Debendra Dash Thank you. And you can call me Sibi :)
Sibeesh VenuPosted Jun 23, 2015, 1:58 AM
Saroj Kumar Sahu Welcome :)
Sibeesh VenuPosted Jun 23, 2015, 1:58 AM
Santhakumar Munuswamy Thank you :)
Debendra DashPosted Jun 23, 2015, 1:32 AM
Nice one sir.......
Saroj Kumar SahuPosted Jun 23, 2015, 1:18 AM
Thanks for sharing.
Santhakumar MunuswamyPosted Jun 22, 2015, 2:15 PM
Thanks for nice one
Sibeesh VenuPosted Jun 22, 2015, 12:27 PM
Debasis Saha Thank you :)
Debasis SahaPosted Jun 22, 2015, 11:45 AM
Good one