onclick
, I need to
- Locate the parent element
- Change its background co开发者_JS百科lor to red
I'm having particular difficulty with the first part.
$('.grid input[type="checkbox"]').click(function(){
$(this).parent().css('background-color', 'red');
});
UPDATE (for attribute use)
function clickHandler() {
$(this).parent().css('background-color', 'red');
}
and then onclick='clickHandler()'
if you attach the event with jquery it's pretty easy
$('#yourid').click(function(){
var parent = $(this).parent();
parent.css("background-color", "red");
});
精彩评论