my code :
$('div').on('click',function(){
checkEl = $(this).attr('id');
console.log(checkEl);
});
So each time div is clicked it schould throw a id of clicked element...
But.. on console.log i got like 3/4/5/6 elements depends from where i cliced...
My output is id of expected div but also parent div are displayed...
How to get id of exactly clicked element?
$(function(){
$('div').on('click',function(){
checkEl = $(this).attr('id');
console.log(checkEl);
})
})
#main{
position:relative;
width:300px;
background-color:red;
}
div{
position:relative;
border:1px solid gray;
padding:15px;
width:100%:
}
#one{
background-color:black;
}
#two{
background-color:blue;
}#three{
background-color:orange;
}#four{
background-color:yellow;
}#fifth{
background-color:purple;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="main">
<div id="one">
<div id="three">
<div id="four">
<div id="fifth">
</div>
</div>
</div>
</div>
</div>