+ 1

While button pressed do...?

Hi, im looking for a solution that i know if a button A is pressed. For example. if(button a is pressed do...) but just if its pressed how can i know that. i need that for: if button a is pressed dont do the function of the eventlisener of button b

31st Oct 2018, 8:20 PM
jack
jack - avatar
5 ответов
+ 7
You can work in html part as : button onclick = function1() JS part : Define function 1. So the crux is that you can use onclick attribute of button tag to call required function and put your conditions in that function.
31st Oct 2018, 8:37 PM
Arushi Singhania
Arushi Singhania - avatar
0
no i cant i want to compare to events how i can do that?
31st Oct 2018, 8:56 PM
jack
jack - avatar
0
like if( button a is pressed and button b not) do ....
31st Oct 2018, 8:57 PM
jack
jack - avatar
31st Oct 2018, 9:28 PM
jack
jack - avatar
0
jack First you have to grab the button a using dom node selection. Then check whether button b is pressed using same. Then have a if condition to check which button is pressed. Use let button1 =document.getElementsByTagName("body").getElementsByTagName("button").[0]; to select the first button in the body tag. Then repeat it to select the next one as button2
5th Nov 2018, 11:04 AM
Maheshwari B
Maheshwari B - avatar