Javascript: Parent element styling
I have same situation like here, but I don't want to write after, but to stylize parent element.
$(".test3").closest(".divouter").after("<div>Foo</div>");
This code from above works, but when I replace after with setAttribute or other st开发者_JS百科uff I'm getting below error:
TypeError: $(".test3").closest(".divouter").setAttribute is not a function
This is message for
$(".test3").closest(".divouter").setattribute("style", "background-color:#DEDEDE;");
Could you help me?
Thanks and I'm sorry for my English, Przemek.
It's returning a jQuery object, not a DOM node. Which means you want jQuery's attr()
method instead.
EDIT: You added some details and made it clear you want the css()
jQuery method.
$(".test3").closest(".divouter").css("background-color", "#DEDEDE");
精彩评论