Techy Techy - 5 months ago 6
jQuery Question

click event for parent and its children jquery

I have a table with

tr
having class
msgdetails
.Inside the
tr.msgdetails
,I have checkbox with class
sel_checkbox
.I have click events for both
tr element and checkbox
and I need to work it independently.If
checkbox
is clicked,event for checkbox should work and the other should work if
tr
is clicked other than checkbox.

My html is like this.

<tr class="msgdetails even" role="row">
<td width="20%">
<div class="checkbox_div">
<input class="sel_checkbox" type="checkbox">
</div>
</td>
<td>some other data</td>
<td>some data</td>
</tr>


My jquery is like this:

$("tr.msgdetails").click(function(e) {
if ((e.target.tagName.toLowerCase()==='checkbox') ||
(e.target.tagName.toLowerCase()==='input'))
{
alert('checked checbox');
}
else
{
alert('row clicked');
}
return false;
});


This works sometime but not working perfectly.Please help me

Answer

Effective way of using is

code

$("tr.msgdetails input[type=checkbox]").click(function(e){
        if(this.checked){
         alert('checked checbox'); 
    }        
   });
Comments