0

In this table, the row has a event in jquery and execute it when i click in the row, inside of the row there are a div... these div has too a event and this execute when i click in the div. but when i click in the div too execute the event of the row....

<table>
 <tr id="one">
  <td>
   <div id="two">
    Hellow world
   </div>
  </td>
 </tr>
</table>

So, when i click in the div, i want execute only the event of the div. how?

Ivan
  • 231
  • 1
  • 5
  • 14
  • `preventDefault` stops the default action from occurring. `stopPropagation` stops bubbling. `stopImmediatePropagation` will stop any other event handlers from firing that are assigned to the same element. – crush Jan 28 '14 at 16:07
  • i edit my post with the events for the div and the row.. – Ivan Jan 28 '14 at 16:19

2 Answers2

5
ev.stopPropagation()

is what you are wondering about.

King Friday
  • 25,132
  • 12
  • 90
  • 84
  • that work in firefox for me, but dont work in chrome – Ivan Jan 28 '14 at 16:26
  • There is this wonderful site, jquery.com, it contains mystical documentation that answers all. I recommend spending 20 minutes of your time to skim the methods available. It will be enlightening and a super time saver rather than using this every time. – King Friday Jan 28 '14 at 18:46
1

Use jquery, and make sure you pass "event" as parameter to the function

 $(document).on('click', '.desplegar' , function(event) {
  .................
  event.stopPropagation();
 });

this will prevent bubbling up of events.

ssilas777
  • 9,672
  • 4
  • 45
  • 68
  • It does not work yet. I was checking in firebug firefox and get this error: "ReferenceError: event is not defined event.stopPropagation();" And after that I guess it works for me because it stops on error and not because event.stopPropagation(); However nothing happens in chorme – Ivan Jan 28 '14 at 16:41
  • are you sure you passing "event" as an parameter, if not you will get not defined error. – ssilas777 Jan 28 '14 at 16:53
  • sorry, I did not see the event as a parameter in your edition. that work good. tnx – Ivan Jan 28 '14 at 16:54