javascript-events

How do I detect if something is being clicked in JavaScript? (without using jQuery) [duplicate]

你。 提交于 2020-04-05 22:58:55
问题 This question already has answers here : JavaScript event registering without using jQuery (6 answers) Closed 6 years ago . I would like to create a boolean function that can detect whether a certain element is being clicked and then output true or false. I want to do this in pure JavaScript with no jQuery, and my idea looks something like this: function clicked(whatever-element-I-want) { if(whatever-element-I-want==clicked) { return true; } else { return false; } } I know this question

How do I detect if something is being clicked in JavaScript? (without using jQuery) [duplicate]

烂漫一生 提交于 2020-04-05 22:58:52
问题 This question already has answers here : JavaScript event registering without using jQuery (6 answers) Closed 6 years ago . I would like to create a boolean function that can detect whether a certain element is being clicked and then output true or false. I want to do this in pure JavaScript with no jQuery, and my idea looks something like this: function clicked(whatever-element-I-want) { if(whatever-element-I-want==clicked) { return true; } else { return false; } } I know this question

animationend event not firing

£可爱£侵袭症+ 提交于 2020-03-21 17:42:06
问题 I am trying to add an animationend event to an element, but the event doesn't get fired. What am I doing wrong, and how can I fix it? JSFiddle var btn = document.getElementById('btn'); var elem = document.getElementById('elem'); var timeOutFunc; btn.addEventListener('click', function() { elem.classList.add('show'); clearTimeout(timeOutFunc); timeOutFunc = setTimeout(function() { elem.classList.remove('show') }, 1000); }); elem.addEventListener('animationend', function(e) { console.log(

Why are two click events registered in this html/css/jquery

一曲冷凌霜 提交于 2020-03-12 01:48:05
问题 I am trying to style a checkbox list. I've added my styles and they appear correctly when rendered. I want to add a class when the label for the checkbox is clicked. This is my markup and here is the same in a jsfiddle. You can see from my fiddle that two click events are registered with just one click. Why? html: <ul> <li> <label for="test_0" class=""> <input id="test_0" name="offering_cycle" type="checkbox" value="1"> Fall </label> </li> <li> <label for="test_1" class=""> <input id="test_1"

Why are two click events registered in this html/css/jquery

╄→гoц情女王★ 提交于 2020-03-12 01:47:41
问题 I am trying to style a checkbox list. I've added my styles and they appear correctly when rendered. I want to add a class when the label for the checkbox is clicked. This is my markup and here is the same in a jsfiddle. You can see from my fiddle that two click events are registered with just one click. Why? html: <ul> <li> <label for="test_0" class=""> <input id="test_0" name="offering_cycle" type="checkbox" value="1"> Fall </label> </li> <li> <label for="test_1" class=""> <input id="test_1"

Append Style to DOM not Replacing Existing

醉酒当歌 提交于 2020-02-23 00:49:30
问题 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: function changeback(onoff) { if(onoff) { document.getElementById("field1").style.background="#fff"; } else document.getElementById("field1").style.background="#000"; } 回答1: Which browser are you using? In Chrome, this works for

Append Style to DOM not Replacing Existing

时间秒杀一切 提交于 2020-02-23 00:46:02
问题 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: function changeback(onoff) { if(onoff) { document.getElementById("field1").style.background="#fff"; } else document.getElementById("field1").style.background="#000"; } 回答1: Which browser are you using? In Chrome, this works for

Append Style to DOM not Replacing Existing

你说的曾经没有我的故事 提交于 2020-02-23 00:42:49
问题 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: function changeback(onoff) { if(onoff) { document.getElementById("field1").style.background="#fff"; } else document.getElementById("field1").style.background="#000"; } 回答1: Which browser are you using? In Chrome, this works for

Reverse event bubbling in javascript

好久不见. 提交于 2020-02-18 10:54:26
问题 As you know, events usually bubble up in javascript, so the event handler of the element that fires the event is executed first, then the event handler of the parent element is called and so on. This behaviour causes some problems on a project I'm currently working on, I would rather have the execution order reversed. I figuered out a solution that is using timeouts: $(element).mouseover(function(){ var that = this; setTimeout(function() { //actual event handler, but references to "this" are

Reverse event bubbling in javascript

假如想象 提交于 2020-02-18 10:54:26
问题 As you know, events usually bubble up in javascript, so the event handler of the element that fires the event is executed first, then the event handler of the parent element is called and so on. This behaviour causes some problems on a project I'm currently working on, I would rather have the execution order reversed. I figuered out a solution that is using timeouts: $(element).mouseover(function(){ var that = this; setTimeout(function() { //actual event handler, but references to "this" are