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 VenuTOP 100Posted Jun 28, 2015, 11:26 PM EDT
VD tripathi Thank you
Vishwakant TripathiPosted Jun 27, 2015, 11:19 PM EDT
Nice
Sibeesh VenuTOP 100Posted Jun 23, 2015, 7:32 AM EDT
Vipul Malhotra Thank you :)
Sibeesh VenuTOP 100Posted Jun 23, 2015, 7:32 AM EDT
Shailesh Uke Thank you :)
Sibeesh VenuTOP 100Posted Jun 23, 2015, 7:32 AM EDT
Jaipal Reddy Thank you :)
Vipul MalhotraPosted Jun 23, 2015, 6:34 AM EDT
Great
Shailesh UkePosted Jun 23, 2015, 6:23 AM EDT
Nice Article............
Jaipal ReddyPosted Jun 23, 2015, 1:25 AM EDT
good one Sibeesh
Sibeesh VenuTOP 100Posted Jun 23, 2015, 1:15 AM EDT
Upendra Pratap Shahi Thanks buddy.
Upendra Pratap ShahiPosted Jun 23, 2015, 12:48 AM EDT
good one Sibeesh Venu
Sibeesh VenuTOP 100Posted Jun 22, 2015, 9:59 PM EDT
Debendra Dash Thank you. And you can call me Sibi :)
Sibeesh VenuTOP 100Posted Jun 22, 2015, 9:58 PM EDT
Saroj Kumar Sahu Welcome :)
Sibeesh VenuTOP 100Posted Jun 22, 2015, 9:58 PM EDT
Santhakumar Munuswamy Thank you :)
Debendra DashPosted Jun 22, 2015, 9:32 PM EDT
Nice one sir.......
Saroj Kumar SahuPosted Jun 22, 2015, 9:18 PM EDT
Thanks for sharing.
Santhakumar MunuswamyPosted Jun 22, 2015, 10:15 AM EDT
Thanks for nice one
Sibeesh VenuTOP 100Posted Jun 22, 2015, 8:27 AM EDT
Debasis Saha Thank you :)
Debasis SahaTOP 100Posted Jun 22, 2015, 7:45 AM EDT
Good one