$(document).ready(function(){
$("input").select(function(){
$("input").after(" Text marked!");
});
$("button").click(function(){
$("input").trigger("select");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<input type="text" value="Hello World"><br><br>
<button>Trigger the select event for the input field</button>
Could someone tell me why select event triggered three times after a button click?
It seems that using IE and Chrome can lead different result.
In IE and Firefox this works fine. Noticed the issue only in Chrome
This seems to be happen because the event gets bubbled up. If you inspect this using Developer tools you can see more information
If you inspect developer tools at last step breakpoint you can notice isTrigger attribute is true meaning it came from the trigger we have defined.
The next two hits of the same breakpoint of $("input").after(" Text marked!");
Developer tools shows almost similar set of attributes. Notice the bubbles attribute is true
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments