An example of the difference between jquery's trigger and triggerHandler

  • 2020-03-30 02:40:26
  • OfStack

Both the trigger and the triggerHandler simulate the occurrence of an event and describe the difference in terms of a specific case
<html lang="en"> 
<meta charset="utf-8"> 
<script src=""></script> 

<input type="checkbox" /> 
<input type="text" id="test"/> 
<input type="button" value="button" id="bnt" onclick="bntClick()"/> 

$( document ).ready(function() { 

function bntClick(){ 

When you click on the checkbox, the checkbox checks and assigns the input[type='text'] value to

The same thing happens when you click input[type='button']

Replace the trigger with a triggerHandler and when you click on the input[type='button'] you just assign the input[type='text'] without checking the checkbox

The triggerHandler blocks the default behavior of the element that binds the event

Related articles: