javascript-events

Checkboxes are being checked before click handler is even called

倖福魔咒の 提交于 2019-12-19 10:25:35
问题 I have the following snippets: http://jsfiddle.net/L7rne/5/ and http://jsfiddle.net/L7rne/6/ It turns out that if you pause execution of the script in the click event handler, then the checkbox is checked, even though there is event.preventDefault() . I tried this in Firefox 7 and Chrome 15 and both behave in the same way. I'm almost sure that it's a correct behaviour but somehow I cannot find any reference why it's like that. Could someone point me in the right direction? EDIT: When you

In jQuery, how to use multiple delay() methods with css()?

筅森魡賤 提交于 2019-12-19 10:14:36
问题 How can i achieve the following, understading the if there was only one delay i could use setTimeout: $(this).css().delay().css().delay().css(); EDIT: The CSS values altered are non-numerical. 回答1: The jQuery ".delay()" API is all about the "effects queue". It actually returns immediately. The only way to do this, if you're not animating the CSS changes, is with "setTimeout()". One thing that might make things more pleasant would be to build your CSS changes into an array: var cssChanges = [

How do I bring an already existing open window to the front on top of other windows from another windows code?

こ雲淡風輕ζ 提交于 2019-12-19 09:29:53
问题 The question was fairly descriptive but I'll describe it further. Basically, I have window1 . Clicking a button link opens window2 . Clicking a button in window2 opens window3 , clicking a button in window3 should bring window2 back to the front of the screen on top of window2 . I'm not sure how this is exactly done, however I have used and played around with focus(), opener and other various methods and I cannot seem to get it to work properly. 回答1: Update : This hasn't worked since Chrome

jQuery Uncaught TypeError in $(selector).on()

做~自己de王妃 提交于 2019-12-19 09:27:06
问题 I am getting the following error: Uncaught TypeError: ((jQuery.event.special[handleObj.origType] || (intermediate value)).handle || handleObj.handler).apply is not a function This is my code and it's somewhere in between the beforeSend and the success calls that the error is happening: $('#main-container').on('click', '#sign-in-btn', function (event) { var username = $('#username-textbox').val(); var password = $('#password-textbox').val(); $.ajax({ url: '/login', method: 'POST', beforeSend:

html onresizeend event, or equivalent way to detect end of resize

送分小仙女□ 提交于 2019-12-19 09:09:18
问题 I'm trying to detect when the onresize event ends in a browser. If I use the "onresize" event, in Firefox it seems to be fired only once, after the resize event ends, which is exactly what I want. But if I try in IE, the "onresize" event gets fired many times during the resize. I also try the "onresizeend" event, advertised in MSDN. But it does not seem to get fired at all, neither in FF, nor in IE. I use the following code: <html> <head> <script> <!-- function doLog(message) { document

Catching all changes to the contents of an input box using Javascript/jQuery

廉价感情. 提交于 2019-12-19 09:06:13
问题 I have a page with an input box, and a function that processes the value of this input box and produces piece of text. I want this text to always be up to date in relation to the contents of the input box, so I've attached a couple of event handlers to it with jQuery to catch any changes: $('#input').bind('keyup cut paste', function(){...}); This works well in most cases. Whenever the user modifies the contents using the keyboard in any way, or right-clicks to use the cut or paste functions,

Submit Event Listener for a form

放肆的年华 提交于 2019-12-19 08:04:07
问题 I've written an event listener for a form submit that is causing me a few issues. When pressing 'enter' inside the text field everything works fine. However, I have an span (with background-image) that submits the form as well via a click event. This is not working properly and I can't figure out why. Here's the basic HTML: <form name="myForm"> <input type="text" name="search" /> <span id="search-button"></span> </form> Here's the JS for the event listener: function evtSubmit(e) { // code e

Maintain focus on an input tag

房东的猫 提交于 2019-12-19 07:39:57
问题 I'm trying to keep focus on an input element with this code: <input onblur="this.focus()" /> But it doesn't seem to work. 回答1: If we just call .focus() right on blur event, it will restore focus, but actually there will be no text cursor. To handle this we have to let element to lose focus and then return it in few milliseconds. We can use setTimeout() for this. $('#inp').on('blur',function () { var blurEl = $(this); setTimeout(function() { blurEl.focus() }, 10); }); Here's working example.

Ensure jQuery event handler execution order

倖福魔咒の 提交于 2019-12-19 07:08:23
问题 I think that event handlers are processed in the order that they are registered. (Is that correct?) If that is the case then if I attach an event handler at the beginning of my script, can I be absolutely certain that it will fire before subsequent handlers attached to the same event? Also do event namespaces have any effect on this? Are event handlers fired in series (one finishes before the next) or in parallel? I want to do this because my script relies on the viewport size, which changes

How can I automatically tab to the next field using jQuery?

人走茶凉 提交于 2019-12-19 07:07:19
问题 In jQuery, how can I trigger the behavior of a user tabbing to the next input field? I've tried this: var e = jQuery.Event("keydown"); e.which = 9; // # Key code for the Tab key $("input").trigger(e); But triggering the event doesn't move the cursor to the next field. I suppose I could move the cursor manually using focus() , but deciding which field should be next is something the browser already knows how to do, so it seems much cleaner to just trigger a tab. Any ideas? 回答1: See the