开发者

Javascript or Jquery - on Checkbox Click, how do I change the parent-element's background color?

onclick, I need to

  1. Locate the parent element
  2. 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");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜