[英]javascript/jquery modify a css class
Before loading my page i want to make some modification on class style. 在加载我的页面之前,我想对类样式进行一些修改。 The style class is included in
MyStyle.css
样式类包含在
MyStyle.css
.divNew {
float: left;
margin: 10px 5px 5px 25px;
}
And loading a new page i want to modify/overload the margin and to add height. 并加载一个新的页面,我想修改/重载边距和增加高度。 Any suggestion?
有什么建议吗? This is what i've tried:
这就是我尝试过的:
function pageLoad() {
var theRules = new Array();
if (document.styleSheets[0].cssRules) {
theRules = document.styleSheets[0].cssRules;
} else if (document.styleSheets[0].rules) {
theRules = document.styleSheets[0].rules;
}
for (n in theRules) {
if (theRules[n].selectorText == 'divNew') { ? ? ? ?
}
}
}
Using jQuery on Document ready you could do something like this. 在Document ready上使用jQuery,你可以做这样的事情。
$(document).ready(function(){
$('.divNew').css('margin','modifications'); // .css('margin','10px 10px 10px 10px');
$('.divNew').height(newHeight); // .height(300)
});
For reference 以供参考
Use the jquery css function. 使用jquery css函数。 It takes an object of CSS properties.
它需要一个CSS属性的对象。
$(document).ready(function(){
$('.divNew').css({
"margin": "10px 5px 5px 25px",
"height": "100px" //change to whatever your height is
});
});
You're over complicating this by a billion percent. 你将这个问题复杂化了10亿。
$('.divNew').css({'height':'2000px', 'width':'2000px'});
just use comma seperated values with the built in jquery css method. 只需使用内置的jquery css方法使用逗号分隔值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.