Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Preventing click event propagation in parents containers ...

$
0
0

Hello everyone, I have a problem with the trap once the click of a html element "li" in javascript, with the following code when I click on an element "li" of folder 4 is unleashed on the click event also elements parent:

<!doctype html><html lang="it"><head><title>Test click</title></head><body><h1>Test click</h1><p>This is a tree!</p><div id="container"><div id="folderstree"><ul id="myFoldersTree"><li id="root" onClick="folder_click(this.id)"><a href="#">root</a><ul id="myGroupNode1"><li id="node1"><a href="#" class="folder1">Files</a></li></ul><ul id="myGroupNode2"><li id="node2"><a href="#">Nuova_cartella</a></li></ul><ul id="myGroupNode5"><li id="node5" onClick="folder_click(this.id)"><a href="#">Nuova_cartella_4</a><li id="node6" onClick="folder_click(this.id)"><a href="#">prova41</a></li><li id="node7"><a href="#">prova42</a></li><li id="node8"><a href="#">prova43</a></li><li id="node9"><a href="#">prova44</a></li></u></li></ul></li></ul></div></div></body></html><script type="text/javascript">

function folder_click(clicked_id){
		alert(clicked_id);
}

</script>

I have already seen many articles but have not managed to avoid the propagation of the event click at the parents tag.
Please I need to solved with the pure javascript, no other libraries. It's very strange this side effect because the event is associated with the single tag html.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>