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)