Sunday, 3 March 2013

The difference between trigger() and triggerHandler()




<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("input").select(function(){
    $("input").after(" Text marked!");
  });
  $("#btn1").click(function(){
    $("input").trigger("select");
  });
  $("#btn2").click(function(){
    $("input").triggerHandler("select");
  });
});
</script>
</head>
<body>

<p>Click each button to see the difference between trigger() and triggerHandler().
<br><br>
<input type="text" value="Hello World">
<br><br>
<button id="btn1">trigger()</button>
<button id="btn2">triggerHandler()</button>

</body>
</html>

trigger() is call a internel code of select event and select a textbox
The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements.

triggerHandler() is call internel code of select event ,but textbox is not select



No comments:

Post a Comment