user1692333
user1692333

Reputation: 2597

How to catch click in all child elements?

Question is simple, but i can't do that... Here my code:

jQuery('nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
});

Upvotes: 0

Views: 83

Answers (2)

bipen
bipen

Reputation: 36541

your codes looks fine.... but i think your are missing the document.ready function

try this

jQuery(function(){  //ready function
  jQuery('nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
  });
});

Upvotes: 1

Rab
Rab

Reputation: 35582

nav must be a class or Id , a nav does not seem to be a standard tag

if its a class name

jQuery('.nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
});

if its an Id

jQuery('#nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
});

Here there is live demo: http://jsfiddle.net/netme/hx8HR/

Upvotes: 1

Related Questions