JQuery - Why does Trigger method call it three times?

Samuel

$(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>

Source

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.

Nipuna

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

enter image description here

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.

enter image description here

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

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why interceptor does run three times?

How to detect trigger method call event in jQuery

Why does call glBindBuffer() two times?

Why does this jQuery pulls only three posts if I call the thumbnail image using JSON?

Why does User Defaults publisher trigger multiple times

Why does this method return three values?

Why does the following trigger need three similar statements at the top?

Why does my tableView function run three times?

Why does JQuery trigger( "remove") do the same as remove() with no trigger?

Why does my ViewController get modally presented two times in a row after a single call to present(_:animated:completion:) method?

Why call method in Tensorflow is called such a few number of times?

Why does it seem to call the wrong method?

Why does the mocked object not get a method call?

Why can call a method that the superclass does not have

Why does this method call fail? (Generics & wildcards)

jQuery does not trigger after ajax call on current page

Why does refactoring by extracting a method trigger a borrow checker error?

Why does specifying a Method Receiver sometimes trigger an 'undefined' error?

why does pastespecial method sometimes throw error 1004 and other times not?

Why does the 'init' method run in two times by the same object?

Why jquery onclick does call action twice

Jquery .click() called three times

trigger method not working in jQuery

Why does this && not trigger as false?

Why this assign does not trigger?

why do I need two click two times to trigger onclick event with angular8 and jquery

Why does adding 1.0/3.0 numeric literal three times evaluates to exactly 1 in Golang?

Why does not 'while(csv.Read())' work two / three times in CsvHelper?

Why does sizeof(array) return three times more than indexes in the array?

TOP Ranking

HotTag

Archive