javascript - OnClick event for div inside lots of container Divs -


i have app i'm developing , need onclick() event fired when <div> clicked.

so in other words,

<div id="panda"></div>   $("#panda").click(function () {         console.log("some text");     }); 

so statement works lets have,

    <div id="panda">     <lots of children>      <div id="koala">     </div>     </lots of children>     </div>    $("#koala").click(function () {         console.log("doesnt work");     }); 

now see life of me can't koala clickable. click event on parents works fine, , click evens empty divs use buttons work fine, reason cant filled child <div> clickable.

any ideas case be?

i tried this,

 $('#panda').click(function(e){         if ($(e.target).is('#koala'))         {             console.log("koala");         }      }); 

but logs every click on parent.

one option listen div children panda.

$("#panda").on('click','div',function() {    console.log($(this).text()+' '+$(this).attr('id'));  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="panda">      <div id="koala">        koala      </div>    <div id="bear">        bear      </div>  </div>


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -