Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickable div inside another clickable div

Tags:

html

css

I have a div that is clickable and when I hover over this div another clickable div appears. However when I try to click this new clickable it will trigger only the parent div clickable. How do I make it to where I can click the new button instead of the parent div clickable? enter image description here

like image 945
Rick Perez Avatar asked Sep 15 '25 12:09

Rick Perez


2 Answers

You have to set stopPropagation to the second div inside the click function.

function div(event){
    event.stopPropagation();
}
<div onClick='div()'>

This will solve your problem

like image 98
Nikesh Kp Avatar answered Sep 17 '25 03:09

Nikesh Kp


I think this is the one you're looking for https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_stoppropagation (in this demo, you need to tick on the checkbox on UI)

You can put e.stopPropagation() in your child element's click.

According to this document

The stopPropagation() method prevents propagation of the same event from being called. Propagation means bubbling up to parent elements or capturing down to child elements.

like image 36
Nick Vu Avatar answered Sep 17 '25 04:09

Nick Vu