jquery - Event listener don't work -


i have next selector "#btn-similar", why listener works:

$("#btn-similar").click(function(e){    console.log("similar click"); }); 

but listener not:

$(document).on("click", "#btn-similar", function(e){    console.log("similar click"); }); 

the html markup is:

<div id="btn-similar" class="details-tab active-nav">    <span class="angle"></span>    <div class="title">overview</div> </div> 

i using jquery 1.10, ideas ?

since both pieces of code correct , work in circumstances, can think of these reasons why second 1 not work:

  1. there's <a> tag or form post in hierarchy causing browser go new page before results of code can seen.

  2. you have more 1 object in page id=btn-similar.

  3. there's script error right before second block of code keeps executing.

  4. you have typo somewhere , code doesn't match desired id. in question, show code refers id=btn-similar, code id=btn-overview.

fyi, can see second block of code work fine here: http://jsfiddle.net/jfriend00/8s7rukt3/ there's oddity in page haven't disclosed.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -