javascript-events

Event bubbling/capturing - where does it start/end?

自作多情 提交于 2019-12-22 05:39:10
问题 I understand that an event has two modes -- bubbling and capturing. When an event is set to bubble, does Javascript checks up to "document" ? When an event is set to capture, does Javascript always starts from "document"? How does Javascript know where to stop/start ? Update: Let's say I have the following code in my body tag. <div id='outer'> <div id='inner'></div> </div> When I set an event to #inner to bubble, does Javascript check up to document or does it stop at #outer? 回答1: Event

Very simple javascript doesn't work at all [duplicate]

∥☆過路亽.° 提交于 2019-12-22 04:39:07
问题 This question already has answers here : Why does jQuery or a DOM method such as getElementById not find the element? (8 answers) Closed 6 years ago . my javascript in .php (static website) file doesn't work. I use there 3 other scripts and they do work, but not this one. The situation is simple The javascript is... var myFile = document.getElementById('myFile'); myFile.addEventListener('change', function() { alert(this.files[0].size); }); and the HTML code in the PHP file is (stripped) <form

Is there a way to handle undefined functions being called in JavaScript?

拟墨画扇 提交于 2019-12-22 04:36:11
问题 If I have a function like the following: function catchUndefinedFunctionCall( name, arguments ) { alert( name + ' is not defined' ); } and I do something silly like foo( 'bar' ); when foo isn't defined, is there some way I can have my catch function called, with name being 'foo' and arguments being an array containing 'bar'? 回答1: There is in Mozilla Javascript 1.5 anyway (it's nonstandard). Check this out: var myObj = { foo: function () { alert('foo!'); } , __noSuchMethod__: function (id,

Using elm higher order functions for keyboard events

♀尐吖头ヾ 提交于 2019-12-22 04:31:18
问题 I am trying to create a higher order function to create functions to capture only a specific key code. The code is inspired on Evan's "onEnter" function from his todomvc implementation which captures only the enter function. onKeyCode : Int -> Msg -> Attribute Msg onKeyCode keycode msg = let captureKey code = if code == keycode then msg else NoOp in on "keydown" (Json.map captureKey keyCode) onEnter = onKeyCode 13 onEsc = onKeyCode 27 And now I want to add that to an input component in the

Using elm higher order functions for keyboard events

无人久伴 提交于 2019-12-22 04:31:16
问题 I am trying to create a higher order function to create functions to capture only a specific key code. The code is inspired on Evan's "onEnter" function from his todomvc implementation which captures only the enter function. onKeyCode : Int -> Msg -> Attribute Msg onKeyCode keycode msg = let captureKey code = if code == keycode then msg else NoOp in on "keydown" (Json.map captureKey keyCode) onEnter = onKeyCode 13 onEsc = onKeyCode 27 And now I want to add that to an input component in the

IE bug triggers click for 2 buttons?

限于喜欢 提交于 2019-12-22 04:14:15
问题 I am trying to trigger the submit button when a user presses enter. Works great for all browsers except Internet Explorer 9. Strange thing is that IE insists on also triggering the click for another button I never told it to. Am I doing something wrong or how to fix this? Below is my code. Pressing enter in IE triggers the submit click as expected, but for some reason also triggers the "some button" click (even without my keypress listener): $('input[type=submit]').click(function () { alert(

How many pixels are scrolled on a website with a mouse wheel down event?

旧巷老猫 提交于 2019-12-22 04:08:09
问题 I'm working on writing a custom scrollbar and am catching the mousewheel event. I'm using this to then adjust the scrollTop of the element I want to scroll on. Is there a standard number of pixels that are scrolled down, or does it vary from system to system? I'm showing 114px in the latest build of Firefox: 回答1: Many mouse drivers let you set the distance scrolled by the mouse wheel, so there is not a standard distance. I'd try your code out for a while and pick a distance that keeps you

javascript text selection events

荒凉一梦 提交于 2019-12-22 04:06:40
问题 This is not just for google chrome extension but also for javascript I am writing a chrome extension in which when a text is highlighted and a context menu is shown i display my item in the context menu which when clicked should process the selected text after bringing up the context menu and selecting my option i get empty object with all values zeros and nulls so i want to implement some mechanism which will buffer the text selection as soon as the user releases the mouse after selecting

How to propagate a click to all divs under cursor?

戏子无情 提交于 2019-12-22 03:54:36
问题 I have a bunch of divs postioned absolutely on top of each other. When I bind a click event to all of them, only the top div responds. How can I send the event to all divs under the cursor? 回答1: Taking FelixKling's suggestion to use document.elementFromPoint() and Amberlamps's fiddle, and employing jQuery for the DOM interactions, I ended up with the following : $divs = $("div").on('click.passThrough', function (e, ee) { var $el = $(this).hide(); try { console.log($el.text());//or console.log

Is there any way to prevent default event and then fire it again with jQuery?

允我心安 提交于 2019-12-22 02:05:41
问题 Basically I have an anchor element, <a href='bla..'>link</a> On click, I first want to do something and only once it's done I want to take the user to the page that it links to. Something like: $('a').click(function(ev){ ev.preventDefault(); //do something here ev.refireDefault(); }); Any suggestions? Update My apologies! My FireFox decided to cache the previous version of JS, so nothing that I tried worked until a simple CTRL+F5 solved the issue. 回答1: Javascript is not multi-threaded. It is