Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable click event on all controls using javascript [duplicate]

Tags:

javascript

I want to use pure javascript (due to application architechture) to disable click event on html page.

I tried

document.body.addEventListener("click", function (evt) { evt.preventDefault(); });

but it still opens my select.

I used select just as an example, I want to do it for every control.

Here is Fiddle

Update Can't use pointer-events:none; because I am using it inside WPF application and sadly it uses frustrating browser known as IE.

like image 282
Imad Avatar asked Oct 20 '16 07:10

Imad


People also ask

How to disable the click event in JavaScript?

To disable clicks with JavaScript, we can write: const foo = document. querySelector('#foo') foo. addEventListener('click', (event) => { event.

How do I disable double click event?

dblclick(function(e){ e. preventDefault(); }); }); Above jQuery code will disable double click event for all the controls on the webpage.

How do I restrict click events?

You can't prevent click with css, you must use javascript. The dislpay:none only hide a element, in this case, a div.

Why do I have to click twice JavaScript?

That's because you're registering an event listener on every click! So your listener executes once more every time you click.


1 Answers

You can easily achieve this by CSS

<select style="pointer-events:none;"> 
   <option>a</option>
   <option>b</option> 
<select>
like image 165
Rishabh Avatar answered Sep 30 '22 14:09

Rishabh