admin管理员组文章数量:1135111
For many reasons I need to disable clicking on certain content within a div
element. Due to clicking ads attacks, for example.
I still want it to be visible tho.
Consider the following snippet :-
<div class="ads">
something should be here, i do not want to be clicked
</div>
how to disable the abilities of left-clicking whithin that div
?
For many reasons I need to disable clicking on certain content within a div
element. Due to clicking ads attacks, for example.
I still want it to be visible tho.
Consider the following snippet :-
<div class="ads">
something should be here, i do not want to be clicked
</div>
how to disable the abilities of left-clicking whithin that div
?
- FWIW, ads are typically written into iframes to prevent the host page from having access – Rob M. Commented Jan 22, 2015 at 7:57
- check this out stackoverflow.com/questions/5259191/… – rasso Commented Jan 22, 2015 at 7:57
6 Answers
Reset to default 211The CSS property that can be used is:
pointer-events:none
!IMPORTANT Keep in mind that this property is not supported by Opera Mini and IE 10 and below (inclusive). Another solution is needed for these browsers.
jQuery METHOD If you want to disable it via script and not CSS property, these can help you out: If you're using jQuery versions 1.4.3+:
$('selector').click(false);
If not:
$('selector').click(function(){return false;});
- Referenced from : jquery - disable click
You can re-enable clicks with pointer-events: auto;
(Documentation)
Note that pointer-events
overrides the cursor
property, so if you want the cursor to be something other than the standard , your css should be place after pointer-events
.
If you want it in pure CSS:
pointer-events:none;
Try this:
pointer-events:none
Adding above on the specified HTML element will prevents all click, state and cursor options.
http://jsfiddle.net/4hrpsrnp/
<div class="ads">
<button id='noclick' onclick='clicked()'>Try</button>
</div>
If using function onclick DIV and then want to disable click it again you can use this :
for (var i=0;i<document.getElementsByClassName('ads').length;i++){
document.getElementsByClassName('ads')[i].onclick = false;
}
Example :
HTML
<div id='mybutton'>Click Me</div>
Javascript
document.getElementById('mybutton').onclick = function () {
alert('You clicked');
this.onclick = false;
}
You can use css
.ads{pointer-events:none}
or Using javascript prevent event
$("selector").click(function(event){
event.preventDefault();
});
How to disable clicking another div click until first one popup div close
<p class="btn1">One</p>
<div id="box1" class="popup">
Test Popup Box One
<span class="close">X</span>
</div>
<!-- Two -->
<p class="btn2">Two</p>
<div id="box2" class="popup">
Test Popup Box Two
<span class="close">X</span>
</div>
<style>
.disabledbutton {
pointer-events: none;
}
.close {
cursor: pointer;
}
</style>
<script>
$(document).ready(function(){
//One
$(".btn1").click(function(){
$("#box1").css('display','block');
$(".btn2,.btn3").addClass("disabledbutton");
});
$(".close").click(function(){
$("#box1").css('display','none');
$(".btn2,.btn3").removeClass("disabledbutton");
});
</script>
本文标签: javascriptHow to disable clicking inside divStack Overflow
版权声明:本文标题:javascript - How to disable clicking inside div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736818816a1954200.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论