event-delegation

jQuery delegate performance on the click event on large lists - slows down if you dynamically add more elements?

老子叫甜甜 提交于 2019-12-31 02:49:10
问题 I have a visual list of items like this: http://jsfiddle.net/viatropos/XCe3T/1/ In the real app, I'm only loading 200 total items. But the problem is the click event takes almost one second to call the handler, even with just 200 items. The mouseover event callback executes immediately no matter how many items are in the list. My question is, shouldn't the delegate method be just as fast no matter how many elements are on the page? All I am doing is this: $("body").delegate("a", "click",

JavaScript: How to simulate change event in internet explorer (delegation)

大城市里の小女人 提交于 2019-12-28 01:29:32
问题 UPDATE: (recap, fiddle and bounty) This question hasn't been getting too much attention, so I'm going to spend some rep on it. I know I tend to be overly verbose in both my answers and questions. That's why I went ahead and set up this fiddle, which is, in my view, a decent representation of the kind of code I'm currently having to use to come close to a bubbling change event. A couple of issues I'm trying to resolve: The pseudo-change event doesn't fire on a select element, unless it looses

JavaScript: How to simulate change event in internet explorer (delegation)

徘徊边缘 提交于 2019-12-28 01:28:27
问题 UPDATE: (recap, fiddle and bounty) This question hasn't been getting too much attention, so I'm going to spend some rep on it. I know I tend to be overly verbose in both my answers and questions. That's why I went ahead and set up this fiddle, which is, in my view, a decent representation of the kind of code I'm currently having to use to come close to a bubbling change event. A couple of issues I'm trying to resolve: The pseudo-change event doesn't fire on a select element, unless it looses

Html onclick attribute vs script's onclick event listener [duplicate]

醉酒当歌 提交于 2019-12-25 18:15:10
问题 This question already has answers here : onclick=“” vs event handler (8 answers) Event listener vs event handler Closed 2 years ago . As a beginner I was just experimenting with various HTML elements and scripts. I then came across the HTML attribute onclick . As I had done more of scripting before my experiments with HTML, I was wondering if there is any difference between calling the function via the DOM itself or through JS/Jquery's event listener. E.g:- html <button onclick="myFunc()" id=

Long press (hold) with jquery hammer.js 2 and event delegation

那年仲夏 提交于 2019-12-23 19:25:24
问题 I recently upgraded to hammer.js 2 and one of the first things a I noticed was that "hold" has been replaced with "press". My old code worked fine with event delegation, but switching to press only seems to work when I put it on a specific element. Note: I use hammer.js through the jquery plugin Hammer.js 1 $(element).hammer().on("hold",callback); Works fine $(rootElement).hammer().on("hold",".elementSelector",callback); Works fine Hammer.js 2 This $(element).hammer().on("press",callback);

Customising event delegates in the jQuery validation plug-in

馋奶兔 提交于 2019-12-23 09:16:51
问题 I am currently setting up the jQuery validation plug-in for use in our project. By default, there are some events automatically set up for handling. I.e. focus in/out, key up events on all inputs fire validation. I want it to only fire when the submit button is clicked. This functionality seems to be in-built into the plug-in, which is making it difficult to do this (without modifying the plug-in code, Not What I Want To Do). I have found the eventDelegate function calls in the plugin code

To delegate typeahead on dynamically generated input

江枫思渺然 提交于 2019-12-23 04:55:10
问题 I have a html table which i am using to enter the inventory details .In this table I have a input box for product name on which I am binding typeahead event of bootstrap.But the problem is that for the first row input box which is already present on the page when it is rendered, typeahead works fine.But when i add new rows for more entries, typeahead does not works with them.I know about the concept of event delegation but the problem is that I don't know how do i implement it in this case

Event delegation in jQuery, how to do it?

孤人 提交于 2019-12-17 17:22:36
问题 In JavaScript i used to use event delegation like this : someDiv.addEventListener('click', function(evt){ if(evt.target.id == "#someChild"){ // Do something.. } else if(evt.target.id == "#anotherChild"){ // Do something else.. } }, false); What's the equivalent of this in jQuery? i know about .on() but how to use it in event delegation ? i mean is this how is it done : someDiv.on('click, '#someChild, #anotherChild", function(evt){ if($(this).is("#someChild")){ // Do something.. } else if($

Native JS equivalent to jQuery delegation

自古美人都是妖i 提交于 2019-12-17 12:02:49
问题 What is the native implementation for event delegation on dynamically created dom elements? I tried looking at the jQuery source but I can't follow the .on method. Note: Currently I attach the event handlers after the dom elements are created, which seems pretty standard but I like the way jQuery .on handles dynamically created elements events with this syntax $( document ).on( "click", ".selector", handler ); . 回答1: What happens is basically this: // $(document).on("click", <selector>,

Keypress event firing only once

时间秒杀一切 提交于 2019-12-13 02:22:12
问题 I am doing like this : $(".classname").bind("keypress",function(){ alert("event happened"); }) code similar to above, working only once, I mean, the first time you type and click enter, it's working, but next time, its not at all reacting. $("#id").bind("keypress",function(){ alert("haiii"); }) the second code working all the time, but the first code working only once. Also if second code is run once, the first code is not even running once. What is the solution? I think I am missing some