I want the button inside the .container
to be clickable, even though it has the pointer-events:none
property.
The context is this: in my real code, I must prevent that a parent div (something to the style of the div that has the class .container
) cannot be dragged, or click pressed and dragged somewhere.
I think if there is a way to solve this, my problem is solved. this is my code:
JavaScript
x
3
1
function myFunction(){
2
alert("click")
3
}
JavaScript
1
9
1
.container{
2
width:30vh;
3
height:30vw;
4
background:red;
5
display:flex;
6
justify-content:center;
7
align-items:center;
8
pointer-events:none;
9
}
JavaScript
1
3
1
<div class="container">
2
<button onclick="myFunction()">click</button>
3
</div>
Advertisement
Answer
Add pointer-events: all
or pointer-events: auto
to the style of your button.
JavaScript
1
3
1
function myFunction(){
2
alert("click")
3
}
JavaScript
1
13
13
1
.container{
2
width:30vh;
3
height:30vw;
4
background:red;
5
display:flex;
6
justify-content:center;
7
align-items:center;
8
pointer-events:none;
9
}
10
11
.container button{
12
pointer-events: all;
13
}
JavaScript
1
3
1
<div class="container">
2
<button onclick="myFunction()">click</button>
3
</div>