Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
Improve this question
I'm trying to understang how events, capturing and bubbling work. And there's some thing that is a bit unclear to me. Where an event is generated? In other words where an event starts going to the target element from? Some articles say events are created by window and then are propagated to document and so on. And some other say events are created in document. The javascript info website has an image where window is included so it makes me think that it is the window that generates events. But document has a .createdEvent method...
Using the document object, we can manipulate the content of the html document (DOM) - add events to elements. With the help of the window object, we can manage windows - it is higher in the hierarchy above the document, so all user events pass through it first.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So from my understanding of event listeners is that the action only applies to the element that you used the event listener on.
But say that I wanted to listen for a click on one element that is in a separate div, but the element I want to apply certain actions on is in a separate div. What would be the best way if possible in doing so?
To help visualize, im looking at this users example.
https://ryannathanwilson.github.io/Rock_Paper_Scissors/
And so from what it looks like it listens for a click on any of the buttons, and then the clicked button shows up in another area and then performs a specific action. Is this possible? Or am I understanding his code incorrectly and the elements that appear at the bottom when clicked is the original element?
You can write a function like this:
function myfunc(){
document.getElementById("abcd").value = "Lorem Ipsum";
}
And call this function on the element you want to listen on:
<button onclick=myfunc()>Click me! </button>
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What's the best way to implement this:
I have multiple elements that will need to do some sort of calculations whenever a global event happens (ex. resize, scroll).
I can either
Add each element to an array then have a single listener for the event and whenever it happens, run a handler that takes the array and loop through each to perform its calc
or
Have each element listen to the single global event
Is there any methods I'm missing?
Add each element to an array then have a single listener for the event
and whenever it happens, run a handler that takes the array and loop
through each to perform its calc
- this; attach a single event handler to a document/body element and do whatever you want in it.
Why: because it has less memory/performance overhead and is a lot more maintainable (which is, in case of JavaScript, often overweights everything else).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I stuck in the problem. I am working on website where I have main page, we can say it Parent page. And through that I am redirecting to other pages in new tab only, to them we can call as Child Page. My question is that, how I can detect on child page that the parent page tab has been closed by user?
I don't know where I can use Javacript or PHP to detecting on every child page.
I want to get the detection on real time. I mean, I do not want to execute function in every 1 minute which check for the value to detect that the parent page was closed.
You can capture the window.onClose event in the parentwindow and send a value to the child window when this happens (set a variable in the child window). Note that the only way to get a reference to the child window is through the return value of window.open(). window.beforeunload might be more widely supported, but it also fires when you go to a different page of your website in the parent page-- this is actually more useful in some cases, especially if the user goes to a new website using the same tab. See How to capture the browser window close event?.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This seems to be impossible with the typical "inspect element" approach, which seems great for HTML and CSS, but that's it. I can't go to a particular element and then link to the particular JavaScript that's controlling it. Is there any way to do this?
As someone else said, there is no precise notion of "the JS controlling an element". There is JS which does something to an element, and there is JS which handles an event on a element. To handle these cases:
In Chrome devtools, select the element, right-click, and select Break on.... This will break when something happens to the element, such as a change in its children or its attributes, and leave you on the line that was making the modification.
Use "Event Listener Breakpoints" and choose to break on a particular event. Then initiate that event on an element which is listening for it, such as by clicking on the element. The debugger will take you to the line handling that event (which might be deep within jQuery, but that's another story).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
After searching for a few hours I could not find the answer I seek, so am submitting a question here.
How would I add on/click popup windows into existing map: http://erichsen-group.com/demoland/vectormaps/vancouver/Vancouver%20Map.html?
An example of the functions and look I am after: http://www.discoverlosangeles.com/
I am not sure which ones you are referring to... but you should use on click listeners
Check out the link below:
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener
The whole idea is that you bind a listener to certain events and when they occur, you fire off some other method. So, if you have a div with some data in it, you can have it reposition to the point of the click, take in some input data and appear. Once the click is lifted or leaves an area (also a listener ;) you can hide the div again.