I am facing an issue where a parent <a>
with an href
attribute contains a child <p>
. My goal is to have a small box appear when the child element is clicked. However, the problem arises when clicking on the child element not only opens the small box but also triggers the parent link to open after a second. I do not want the parent link to open when clicking on the child element. Even after adding event.stopPropagation()
and adjusting the z-index
property, the issue persists.
You can view a live example in my JS Fiddle demo, but below is my current code:
.parent {
background-color: blue;
display: inline-block;
width: 400px;
height: 300px;
z-index: 1;
}
.child {
color: black;
background-color: yellow;
display: inline-block;
width: 100px;
height: 50px;
z-index: 2;
}
[title] {
position: relative;
display: inline-flex;
justify-content: center;
}
.child:focus::after {
content: attr(title);
position: absolute;
top: 90%;
color: #000;
background-color: #fff;
border: 1px solid;
width: fit-content;
padding: 3px;
font-size: 10px;
z-index: 20;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<a class="parent" href="https://www.google.com/">
<p class="child" title="This is mobile tooltip" tabindex="0" (click)="$event.stopPropagation();">Click</p>
</a>
Note: Using jQuery is not an option for me.
Thank you.