dom-events

How to trigger click event manually?

巧了我就是萌 提交于 2020-08-02 07:24:32
问题 I am trying to trigger a document click programatically. My test-comp are shown in multiple places in a page and I want to hide them all when the test-comp is clicked or a document click is fired. @Component({ selector: 'test-comp', template: `<div *ngIf="showMe">stuff</div> and more…` }) export class TestComponent { showMenu: boolean; constructor(public elementRef: ElementRef) { } @HostListener('document:click', ['$event']) documentClick(event: MouseEvent) { //hide my component when there is

Why does JSON.stringify only show the isTrusted member of a click event?

坚强是说给别人听的谎言 提交于 2020-07-20 07:39:08
问题 HTML: <button onclick="foo(event);">Test</button> Javascript: window.foo = function(event) { console.log(JSON.stringify(event)); } Console Result: {"isTrusted":true} It is happening on Chrome. I haven't tested other browsers yet. 回答1: There are a number of reasons why some properties do not get included in JSON.stringify: They might be function s, which cannot be stringified They might belong to the prototype (i.e. class) of an object, rather than directly belonging to the object itself. If

Click event coordinates in SVG

白昼怎懂夜的黑 提交于 2020-07-09 05:51:08
问题 This HTML containing SVG: <div class="container"> <div class="spacer"></div> <svg> <g id="polygonGroup" transform="translate(80, 50)"> <polygon points="-60,-10 -35,-30 -10,-10 -10,30 -60,30"></polygon> <polygon points="10,-10 35,-30 60,-10 60,30 10,30"></polygon> <polygon class="origin" points="-4,0 0,4 4,0 0,-4"></polygon> </g> <g id="textGroup" transform="translate(80, 50)"> <text x="-35" y="10">Text</text> <text x="35" y="10">Text</text> </g> </svg> </div> and this simple jQuery click

Calling a function in React

狂风中的少年 提交于 2020-07-04 08:30:09
问题 I'm a beginner in React, and I'm a little confused about calling a function in React. I saw the following ways and I don't know when to use each and which one. handleAddTodo ={this.handleAddTodo} handleAddTodo ={this.handleAddTodo()} handleAddTodo ={handleAddTodo} handleAddTodo ={this.handleAddTodo} handleAddTodo ={handleAddTodo()} Are these interchangeable? Could I do that to handle an event, the same way to call a function? 回答1: Are these interchangeable? Short answer: No. Let's take a look

Calling a function in React

六月ゝ 毕业季﹏ 提交于 2020-07-04 08:26:48
问题 I'm a beginner in React, and I'm a little confused about calling a function in React. I saw the following ways and I don't know when to use each and which one. handleAddTodo ={this.handleAddTodo} handleAddTodo ={this.handleAddTodo()} handleAddTodo ={handleAddTodo} handleAddTodo ={this.handleAddTodo} handleAddTodo ={handleAddTodo()} Are these interchangeable? Could I do that to handle an event, the same way to call a function? 回答1: Are these interchangeable? Short answer: No. Let's take a look

Killing a JavaScript function which runs infinite

≯℡__Kan透↙ 提交于 2020-07-03 06:34:12
问题 As an example var runInfinite = function(){ while(1) { // Do stuff; } }; setTimeout(runInfinite, 0); Is it possible to break this runInfinite function form running infinite? I mean is it possible to kill this function from another function without using a flag or return statement? 回答1: The answer is no. Since JavaScript is single-threaded ( unless you are using some less common implementation which I doubt ) nothing can break a loop ( or any other block of code ) from outside. 回答2: There is

Cannot add click events to list items

时光总嘲笑我的痴心妄想 提交于 2020-06-27 07:25:32
问题 This is my first foray into using Javascript with HTML. I'm trying to add click events to the list items in an ordered list, but something about the way I'm doing it isn't working. Can somebody shed some light on this for me? I create a function in my head that should delegate all click events on the list items of a specified list to a given function, and in that given function I try to raise a simple alert with the text of the list item. Eventually I want to do more, but I'm just trying to

HTML5 dragend event firing immediately

↘锁芯ラ 提交于 2020-06-24 21:48:34
问题 I have several draggable elements <div Class="question-item" draggable="true">Box 1: Milk was a bad choice.</div> <div class="question-item" draggable="true">Box 2: I'm Ron Burgundy?</div> <div class="question-item" draggable="true">Box 3: You ate the entire wheel of cheese? </div> <div class="question-item" draggable="true">Box 4: Scotch scotch scotch</div> And I have the following event handlers: var $questionItems = $('.question-item'); $questionItems .on('dragstart', startDrag) .on(

HTML5 dragend event firing immediately

守給你的承諾、 提交于 2020-06-24 21:47:54
问题 I have several draggable elements <div Class="question-item" draggable="true">Box 1: Milk was a bad choice.</div> <div class="question-item" draggable="true">Box 2: I'm Ron Burgundy?</div> <div class="question-item" draggable="true">Box 3: You ate the entire wheel of cheese? </div> <div class="question-item" draggable="true">Box 4: Scotch scotch scotch</div> And I have the following event handlers: var $questionItems = $('.question-item'); $questionItems .on('dragstart', startDrag) .on(

Re-bind onclick, on* event listeners for debugging

☆樱花仙子☆ 提交于 2020-06-23 08:13:26
问题 I want to monkeypatch event listener registrations. I found this answer showing how to do it for addEventListener : const nativeEventListener = EventTarget.prototype.addEventListener; EventTarget.prototype.addEventListener = function(...args) { if (this.matches('div') && args[0] === 'click') { console.log('listener is being added to a div'); debugger; } nativeEventListener.apply(this, args); } // then, when an event listener is added, you'll be able to intercept the call and debug it: