简体   繁体   English

使用jQuery编辑现有的内联样式?

[英]edit existing inline style using jquery?

I have some html which seems to default to : 我有一些HTML似乎默认为:

<ul style="top: 72px; visibility: hidden;">

But i need Jquery to rescue me and change top: 72px to top: 37px 但是我需要Jquery来救我,并将top:72px更改为top:37px

Is this possible? 这可能吗? as in Firefox 37px seems to show up but in IE7 it shows up as 72px 如在Firefox中显示37px,但在IE7中显示为72px

Thanks 谢谢

edit: added more info 编辑:添加了更多信息

the ul id = treemenu1 ul id = treemenu1

and its parent element is div class = treemenu 它的父元素是div class = treemenu

$('#treemenu1').css({ top: 37 });

Should work fine. 应该工作正常。

jsFiddle of POC. POC的jsFiddle

I would select your ul by id: 我会通过ID选择您的ul:

$("#treemenu1").css("top", "37px");

Also note that you can update multiple css properties at once by passing an object in, whose keys and values correspond to css properties, and their new values: 还要注意,您可以通过传入一个对象(该对象的键和值与css属性及其新值相对应)来一次更新多个css属性:

$("#treemenu1").css({ "top": "37px", "bottom": "20px" });
$("ul").css("top", "37px");//this should work in all browsers.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM