skd
skd

Reputation: 13

Event on of jquery?

$('body').on('click', '.conversation_item', function (e) {
    e.preventDefault();
    console.log("go");

});
$('body').on('click', '.conversation_item > span', function () {
    console.log("true");
});

when i click element .conversation_item > span jquery active both conversation_item and conversation_item > span . I don't want it but I must use on event. Help me.

Upvotes: 1

Views: 48

Answers (3)

Tudor Leustean
Tudor Leustean

Reputation: 567

You should stop event propagation. Check this out.

http://api.jquery.com/event.stoppropagation/

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

You need to stop event propagation to child element click:

$('body').on('click', '.conversation_item > span', function (event) {
   event.stopPropagation();
   console.log("true");
});

Upvotes: 1

Umesh Sehta
Umesh Sehta

Reputation: 10683

You need to use event.stopPropagation() on click event

$('body').on('click', '.conversation_item > span', function (e) {
 e.stopPropagation()
  alert("true");
});

Demo

Upvotes: 2

Related Questions