Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Trigger function in JQuery

    • 0
    • 0
    • 0
    • 12
    • 0
    • 0
    • 0
    • 0
    • 354
    Comment on it

    Trigger function has an interesting concept as it is used to execute all handlers and behaviors attached to the matched elements for the given event type.

    For example, If I want to have a click event on a button without clicking, we can use this function for that.

    Working example is given below:
    HTML :

    <button>Not Clicked</button>
    <button>Clicked</button>
    <div><span> adding comment </span></div>
    <div><span>adding comment second </span></div>
    

    JQuery:

    $( "button:first" ).click(function() {
      $( "span:first" ).append("+ adding comment");
    });
    
    $( "button:last" ).click(function() {
      $( "button:first" ).trigger( "click" );
     $( "span:last" ).append("+ adding comment second ");
    });
    

 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: