Skip to content
Advertisement

Tag: dom-events

JavaScript add events cross-browser function implementation: use attachEvent/addEventListener vs inline events

In order to add events we could use this simple first solution: or this second solution (that adds inline events): These are both cross-browsers and can be used in this way: Since I have the feeling attachEvent/addEventListener are used more around in events handling implementations, I’m wondering: Are there any disadvantages/drawbacks against using the second solution that I might better

On Text Highlight Event?

I’m curious if anyone knows how I would trigger a function to run if/once the user finishes selecting text on the web page? I would like the user to be able to select text, and after a short delay(or immediately, at this point it doesn’t matter much) an overlay button appears near the text that the user can then click

Append Style to DOM not Replacing Existing

How can I append style element to DOM without eliminating existing style on the item (eg color, text-align, etc)? The event calls the function, but the problem is ‘Style’ gets completely replaced with the single item instead. I have simple code triggered on the event: Answer Which browser are you using? In Chrome, this works for me: When I click

window.onload vs $(document).ready()

What are the differences between JavaScript’s window.onload and jQuery’s $(document).ready() method? Answer The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded. The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the

Remove key press delay in Javascript

I have the following problem: I’m trying to write a Javascript game, and the character is being controlled by the arrow keys. The problem is, when one keeps the key pressed, there is a short delay between firing the first keypress and the repeated keypress. Also, when one presses the “right arrow key” and keeps it pressed, and then presses

Firing DOM mouse events programmatically from JavaScript

Is it possible to programmatically fire mouse events in DOM? My sample case would be the following: Whenever the user clicks the div over an iframe, I would like to somehow propagate the event to the iframe, too. (Here we assume that the iframe src is in the same domain.) Answer Whilst you can inject events into browsers’ event-handling systems

Is there any possibility of two asynchronous Javascript function instances executing two blocks of code at the same time?

I understand that Javascript doesn’t have multiple threads, but I’d like to know if the following code has any chance of breaking. My understanding is that unless an asynchronous function is called, such as setTimeout or an AJAX call, that once a block of code starts executing there’s no way for it to pause until it completes or does call

How to get caller element using JavaScript?

I have a table with id “tbl” and it has 2 rows and 3 cols. Each cell (td) has an explicitly defined id. Also, the table has an onclick event that calls a function foo(). The onclick() would be generated whenever any cell is clicked. The table tag is: I also tried javascript:foo(this) I want to find out the id

Advertisement