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
.
To disable clicks with JavaScript, we can write: const foo = document. querySelector('#foo') foo. addEventListener('click', (event) => { event.
dblclick(function(e){ e. preventDefault(); }); }); Above jQuery code will disable double click event for all the controls on the webpage.
You can't prevent click with css, you must use javascript. The dislpay:none only hide a element, in this case, a div.
That's because you're registering an event listener on every click! So your listener executes once more every time you click.
You can easily achieve this by CSS
<select style="pointer-events:none;">
<option>a</option>
<option>b</option>
<select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With