How to control click event of <li> conditionally?

  • A+

I have a ul tag and several li tags inside that. When I click on a li some action is occurs using Jquery click event. For each li the action is different.

Then I added a text box into each li. When ever I click on the text box to enter something the li click event gets triggerd.

How do I prevent li click event when I am clicking in the text box?

HTML code:

<ul id="myul">     <li id="myli">          <div>             // some codes              <span>                  // some codes             </span>              <input type="text" id="myTextbox" />              // some codes                                                                  </div>     </li>      // other li tags </ul> 

JQuery click event:

$('body').on('click', '.myli', function (evt)          // my actions     }); 


maybe you have to try j query method which is e.stopPropagation(); here is a code

The event.stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent event handlers from being executed.

 $("input").click(function(e) {     e.stopPropagation();   }); }); 

here is a link for more link


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: