Reputation: 22587
On click of checkbox, I need to retrieve immediate parent span's class value:
The checkbox column is defined in an ItemTemplate as:
<asp:CheckBox CssClass='<%# Eval("ID") %>' Checked='<%# Eval("IsSelected") %>'
Text="" runat="server" onclick="CartItemCheckClicked()" />
The JS function is defined as:
function CartItemCheckClicked() {
alert($(this).parent().attr('class')); //Undefined
//alert($(this).attr('id')); //Undefined
}
Ouput Sample HTML
<span class="283"><input type="checkbox" onclick="CartItemCheckClicked();" checked="checked" name="grvShoppingCart$ctl02$ctl00" id="grvShoppingCart_ctl00_0"></span>
But the result is always 'undefined'. How do I access the checkbox or parent span?
Upvotes: 2
Views: 3163
Reputation: 53685
Just pass checkbox to click function:
onclick="CartItemCheckClicked(this);"
And in js file than:
function CartItemCheckClicked(chk) {
alert($(chk).parent().attr('class'));
}
Upvotes: 3