Umair Umair - 1 year ago 59
HTML Question

Bind event on LI not not on Anchor tag inside that LI - jQuery

I have this kind of HTML

<li class="one-reference per-reference ui-draggable" item-id="8" style="position: relative;">
<a class="moduleItemTitle" href="http://localhost/derrickpang/index.php?option=com_k2&amp;view=item&amp;id=8">Knee pains</a>
<span class="moduleItemDateCreated">Written on Wednesday, 19 October 2016 05:58</span>
<span class="moduleItemHits">Read 393 times</span>
<div class="clr"></div>

I have bind event on all LIs with class

I do not want to call function
when clicked on
tag with class
I just want to open that link in
as normal behaviour of anchor tag.

Here is what I have tried

jQuery(".per-reference").bind("click", openRefModal);
jQuery(".per-reference .moduleItemTitle").unbind("click", openRefModal);

Answer Source

Just add below code for a tag moduleItemTitle class

jQuery(".per-reference").bind("click", openRefModal);
jQuery(".per-reference .moduleItemTitle" ).click(function( event ) {

Now a tag is released from click event.

Here is the details about jQuery stopPropagation

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download