开发者

Javascript: Parent element styling

开发者 https://www.devze.com 2023-03-24 07:30 出处:网络
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>\");

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");
0

精彩评论

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

关注公众号