Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use event.data property in jQuery ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 319
    Comment on it

    Hi Reader's,
      Welcome to FindNerd, in this blog I will guide you to use event.data Property in Jquery.

    Basically event.data property is used when the current executing handler is bound. so we can say that it is an optional object of data passed to an event method when the current executing handler is bound.

     syntax of  event.data property

    event.data

    event is a required parameter here.

     you can see below example:

    <!DOCTYPE html>
    <html>
    <head>
      <!-- here add jquery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      //call paragraph to event
        $("p").each(function(i){
          //call  event.data property on click
            $(this).on("click", {x:i}, function(event){
              //alert massage
                alert("The value is " + $(this).index() + ". test paragraph has data value is: " + event.data.x);
            });
        });
    });
    </script>
    </head>
    <body>
    
    <!-- Click on each p element to return the data passed with the on() method -->
    
    <p>Tset paragraph.</p>
    <p>Another tset paragraph.</p>
    <p>Another tset paragraph.</p>
    
    </body>
    </html>
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: