event-delegation

Most efficient way to dynamically bind event handlers

只谈情不闲聊 提交于 2019-12-12 08:33:08
问题 Problem: I need to bind any number of event handlers to any number of elements (DOM nodes, window , document ) at dynamically runtime and I need to be able to update event binding for dynamically created (or destroyed) nodes during the lifetime of my page. There are three options that I can see for tackling this problem: I) Event delegation on window II) Direct event binding on each node III) Event delegation on common ancestors (which would be unknown until runtime and would potentially need

Correct syntax for defining an event delegator

爱⌒轻易说出口 提交于 2019-12-12 03:53:24
问题 Normally you write a handler for a button click like this: $(document).ready(function() { $("button").click(function() { doSomething(); }); }); But in the case of an event delegator, to respond to an event with a function such as this: function doSomething(event) { if (ev.target.id == 'button1' ) { //do your stuff console.log('#button1 click'); } else { console.log('not a #button1 click'); } } What I'm confused about is the correct syntax for defining the event that calls this delegator

jQuery event delegation in 1.7.2

為{幸葍}努か 提交于 2019-12-12 03:52:54
问题 Is there any way to delegate an event using jQuery that will correspond to all elements on the page that match the selector, other than delegating from $(document) ? Since that's probably poorly worded, here's the rub: There used to be jQuery.live that delegated events to all elements that matched the selector. This was superseded by jQuery.delegate which delegated events within a specific context selector to its children, which in turn was superseded by jQuery.on , which does effectively the

click Event is not delegated in chrome

跟風遠走 提交于 2019-12-11 07:55:15
问题 In my application I create some new elements and append them to the page according to use's operation, var dv=document.createElement('div'); //set styles for the dv ..... After create this div element,I will add some event to it: MyLib.Event.addDomListener(dv,'click',function(e){ console.info('click'); }); MyLib.Event.addDomListener(dv,'mousedown',function(e){ console.info('mousedown'); }); This is the generated result in the page(a div contain a img tag and a span tag): After the page loaded

Can i (in javascript) write an event or a function that automatically applies to one kind of html tag? [duplicate]

大兔子大兔子 提交于 2019-12-11 06:43:46
问题 This question already has answers here : JS event listener for a type of element? (5 answers) Closed 2 years ago . I was looking for a way to apply an onclick(); or a function to all the <span></span> tags in my page, even the ones which are created later, like a universal order for all of this type of html tag. despite of ID class type or any other attribute only tag name. Edit: Answered by @mhodges by introducing this note that you should use toLowerCase() too 回答1: I don't know plain

How to solve flicker on iPad when event delegation is used?

主宰稳场 提交于 2019-12-10 10:25:21
问题 When using the method of event delegation, we set the event handler on a higher level element (parent or grandparent), but this has an issue on iPad's Safari: if the parent element has a click handler, when the user touches anything inside this element, the whole region will gray out (on iOS 5.1), or flicker (on iOS 6). So, if the parent or grandparent is 300 x 300 pixel, and the link is just a word, say 60 x 20 pixel, then when the user touches any where inside the parent (except the link),

How do I register a javascript event handler to an element that hasn't been added to the page yet

巧了我就是萌 提交于 2019-12-10 09:47:09
问题 I'm trying to build a greasemonkey script which will dynamically create tables of data based on user interaction with... other dynamically created tables of data. My problem is that I'm having to make two passes every time I create a table: one to create the table, and another to go grab all of the objects in the table I want to add event handlers to (by id) and add the various event handlers to them. If I attempt to, say, add an onClick event to a table td before I've created the table and

How to solve flicker on iPad when event delegation is used?

筅森魡賤 提交于 2019-12-05 19:57:51
When using the method of event delegation, we set the event handler on a higher level element (parent or grandparent), but this has an issue on iPad's Safari: if the parent element has a click handler, when the user touches anything inside this element, the whole region will gray out (on iOS 5.1), or flicker (on iOS 6). So, if the parent or grandparent is 300 x 300 pixel, and the link is just a word, say 60 x 20 pixel, then when the user touches any where inside the parent (except the link), the whole 300 x 300 region will either gray out or flicker, depending on the iOS version. This is an

MooTools - Programmatically fired events not working with event delegation

大兔子大兔子 提交于 2019-12-03 13:04:24
问题 Would really appreciate if anyone can help me figure out why I am unable to fire events programmatically when using event delegation in MooTools (from the Element.Delegation class). There is a parent <div> that has a change listener on some child <input> elements. When the change event is triggered by user actions, the handler on the parent div gets triggered, but when I fire it programmatically with fireEvent on any child input, nothing happens. The basic setup is: html <div id="listener">

jquery Event Delegation

爷,独闯天下 提交于 2019-12-02 19:20:45
问题 I am attempting to rewrite a snippet of code using event delegation (in the hopes that it will stop conflict with another snippiet of js). but I've broken the code Original //to scale up on hover var current_h = null; var current_w = null; $('.piccon').hover( function(){ current_h = $(this, 'img')[0].height; current_w = $(this, 'img')[0].width; $(this).stop(true, false).animate({width: (current_w * 2.7), height: (current_h * 2.7)}, 900); }, function(){ $(this).stop(true, false).animate({width