Овај сајт ће имати ограничену функционалност док га будемо ажурирали у циљу побољшања вашег искуства. Ако неки чланак не реши ваш проблем и желите да поставите питање, на располагању ће вам бити наше заједнице подршке @FirefoxSupport на Twitter-у и /r/firefox на Reddit-у.

Претражи подршку

Избегните преваре подршке. Никада од вас нећемо тражити да зовете или шаљете поруке на број или да делите личне податке. Пријавите сумњиве радње преко „Пријавите злоупотребу” опције.

Сазнај више

Why do jquery 2.2.4 .on('click') listeners not trigger upon clicking dynamically loaded children of the element specified in the finder?

  • 1 одговор
  • 1 има овај проблем
  • 5 прегледа
  • Последњи одговор послао michaelrstewart1

more options

I am using jQuery 2.2.4 to listen for a click on an element within a div. The element within the div is dynamically loaded.

Consider the following div element. (I'm having to remove the starting characters from the tags so the code shows up here)

div id='view_dashboards_pane'>

/div>

Content is loaded into the above div via an ajax call, resulting in this:

div id='view_dashboards_pane'>

    i class="dashboard_user_edit_label">mode_edit</i>

/div>

The below script is present on the initially loaded page and will successfully trigger upon clicking the dynamically loaded element in Chrome and Edge, however the click does not register in Firefox. Looking at the "Events" section for the <i> element in Firebug it appears that the listener is attached, but the click event does not register.

script type='text/javascript'>

    $('#view_dashboards_pane').on('click','.dashboard_user_edit_label',function(){
        console.log('Clicked');
    });

/script>

There are no errors in the console and all other javascript/jQuery continues to function within the browser. How does Firefox handle these events differently, and how would I work around this?

I am using jQuery 2.2.4 to listen for a click on an element within a div. The element within the div is dynamically loaded. Consider the following div element. (I'm having to remove the starting characters from the tags so the code shows up here) div id='view_dashboards_pane'> /div> Content is loaded into the above div via an ajax call, resulting in this: div id='view_dashboards_pane'> i class="dashboard_user_edit_label">mode_edit</i> /div> The below script is present on the initially loaded page and will successfully trigger upon clicking the dynamically loaded <i> element in Chrome and Edge, however the click does not register in Firefox. Looking at the "Events" section for the <i> element in Firebug it appears that the listener is attached, but the click event does not register. script type='text/javascript'> $('#view_dashboards_pane').on('click','.dashboard_user_edit_label',function(){ console.log('Clicked'); }); /script> There are no errors in the console and all other javascript/jQuery continues to function within the browser. How does Firefox handle these events differently, and how would I work around this?

Измењено од стране michaelrstewart1

Сви одговори (1)

more options

Wow, if I change the tag from "i" to "button" it works, but unfortunately I need to remain "i". What is going on there?

Измењено од стране michaelrstewart1