event-handling

jQuery .on() method doesn't see new elements

五迷三道 提交于 2019-11-27 12:33:51
I'm getting a JSON element and building a list from its items like this: getTitles: function(data) { data = data || {}; var list = []; $.getJSON( '/titles', data, function(data) { $.each(data.data, function(key, val) { list.push( '<li><a href="'+ val.href +'">'+ val.title +'</a><span class="count">'+ val.count +'</span></li>' ) }); $('#title-items').html(list.join('')); } ); } And I'm binding click event for a elements like this: $('a').on('click', function(e) { alert('clicked'); e.preventDefault(); }); Old a elements shows alert but new ones follow URL. Event handler doesn't work for new ones

Asynchronous or Synchronous calling of event handlers in javascript

你说的曾经没有我的故事 提交于 2019-11-27 12:22:39
问题 Are event handlers executed synchronously or asynchronously in JavaScript? Here is JS bin which is showing that event handler is executed synchronously. Code: $('#toclick').bind('custom', function() { for (var i=0; i<100000; i++) {} console.log('Inside click handler'); }); $('#toclick').trigger('custom'); console.log('Outside click handler'); Output: Inside click handler Outside click handler This means if we trigger an event, the code below it won't be executed unless all the event handlers

Handling standby on iPad using Javascript

不打扰是莪最后的温柔 提交于 2019-11-27 12:12:42
Regarding iPad events, how to determine if/when the iPad is changing from an awake state to a standby state? What I would like to do is put my Mobile-Safari web app in a locked state whenever the iPad becomes inactive/standby and ask for a PIN when it becomes awake again. I agree that there really ought to be some signal you can hook on to to know when an application goes to sleep and when it wakes up, but you should be able to figure out when Safari wakes up indirectly. When the webview goes into the background, Safari puts everything in it to sleep. It pauses any video, defers network

Notify when event from another class is triggered [duplicate]

江枫思渺然 提交于 2019-11-27 12:07:16
问题 This question already has answers here : How to raise an event on Property Change? (2 answers) Closed 4 years ago . I have class A { B b; //call this Method when b.Button_click or b.someMethod is launched private void MyMethod() { } ?? } Class B { //here i.e. a button is pressed and in Class A //i want to call also MyMethod() in Class A after the button is pressed private void Button_Click(object o, EventArgs s) { SomeMethod(); } public void SomeMethod() { } ?? } Class A has a instance of

Determine mouse position outside of events (using jQuery)?

*爱你&永不变心* 提交于 2019-11-27 12:02:40
I need to get a hold of the absolute mouse position / coordinates (X and Y) using (preferably) jQuery like in this tutorial but outside of any JavaScript event. Thank you. Not possible. You can however use the same approach in the tutorial to store the position in a global variable and read it outside the event. Like this: jQuery(document).ready(function(){ $().mousemove(function(e){ window.mouseXPos = e.pageX; window.mouseYPos = e.pageY; }); }) You can now use window.mouseXPos and window.mouseYPos from anywhere. eyelidlessness This started as a comment on Chetan Sastry's answer , but I

Should WebSocket.onclose be triggered by user navigation or refresh?

你说的曾经没有我的故事 提交于 2019-11-27 12:00:07
问题 Part 1: Expected behaviour? I'm seeing some inconsistent browser behaviour between Firefox and Chrome in relation to the onclose handler being called. It seems that Chrome does not trigger an onclose if it was caused by a user page navigation/refresh. However, Firefox does trigger the onclose . It seems to me that Firefox may be behaving correctly here: When the WebSocket connection is closed, possibly cleanly, the user agent must create an event that uses the CloseEvent interface, with the

ASP .NET Button event handlers do not fire on the first click, but on the second click after a PostBack

元气小坏坏 提交于 2019-11-27 11:54:41
Background: I am customizing an existing ASP .NET / C# application. It has it's own little "framework" and conventions for developers to follow when extending/customizing its functionality. I am currently extending some of it's administrative functionality, to which the framework provides a contract to enforce implementation of the GetAdministrationInterface() method, which returns System.Web.UI.Control . This method is called during the Page_Load() method of the page hosting the GUI interface. Problem: I have three buttons in my GUI, each of which have been assigned an Event Handler. My

How to click a browser button with JavaScript automatically?

与世无争的帅哥 提交于 2019-11-27 11:53:21
How to click a button every second using JavaScript? John Hartsock setInterval(function () {document.getElementById("btnMakePaperclip").click();}, 1000); This will give you some control over the clicking, and looks tidy <script> var timeOut = 0; function onClick(but) { //code clearTimeout(timeOut); timeOut = setTimeout(function (){onClick(but)},1000); } </script> <button onclick="onClick(this)">Start clicking</button> document.getElementById('youridhere').click() This would work setInterval(function(){$("#myButtonId").click();}, 1000); Footer You can use setInterval(function(){ document

Gesture problem: UISwipeGestureRecognizer + UISlider

不打扰是莪最后的温柔 提交于 2019-11-27 11:49:55
Got a gesture related problem. I implemented UISwipeGestureRecognizer to get swipe left and right events and that is working fine. However the problem I'm facing is that the UISlider's I have in the same view are not playing nice. The sliding motion of the sliders is being mistaken as a swipe left/right. Any one experienced this problem before, got any ideas how to correct it? Many thanks. Here is the code contained within the view controller: - (void)viewDidLoad { [super viewDidLoad]; //Setup handling of LEFT and RIGHT swipes UISwipeGestureRecognizer *recognizer; recognizer = [

Accessing an object's property from an event listener call in Javascript

白昼怎懂夜的黑 提交于 2019-11-27 11:48:03
问题 Below I am creating an object in Javascript. Within the constructor I am setting up an event listener. The problem is that when the event gets fired, this.prop cannot be found, and undefined prints out. How do I solve this? var someObj = function someObj(){ this.prop = 33; this.mouseMoving = function() { console.log(this.prop);} document.getElementById("someDiv").addEventListener('mousemove', this.mouseMoving, true); } 回答1: When the event handler gets called, "this" no longer references the