如何通过jQuery向类中添加CSS
How to add CSS to a class through jQuery?
我使用jQuery Mobile为一个简单的移动应用程序,我想添加一个CSS到它。目前,我有以下CSS类:
.home-button-edited {
border: 1px solid #2373A5;
margin-top: 1px !important;
background:#3496da;
}
然后在JS部分我有以下代码段:
var viewport = {
width: $(window).width(),
height: $(window).height()
};
document.addEventListener("deviceready", setHomeButton, false);
function setHomeButton() {
var difference = viewport.width - 85;
$('.home-button-edited').css("left", "difference !important");
}
关键是,我想添加一个left属性到.home-button-edited,用我在difference变量中得到的值,它也应该有一个重要的属性。什么好主意吗?
$('.home-button-edited').css("left", difference+"!important");
或
$('.home-button-edited').style.setProperty( 'left', difference, 'important' );
您可以使用:
$('.home-button-edited').css('cssText','left: '+difference+'px !important');
函数出错
function setHomeButton() {
var difference = viewport.width - 85;
$('.home-button-edited').css("left", difference + " !important");
}
相关文章:
- 如何添加CSS&JavaScript进入Windows窗体应用程序C#.net
- 对于每个json结果,使用类jquery添加css
- 为未标记的文本添加CSS样式
- 在WordPress中使用JavaScript在html元素上添加css类
- jQuery检查CSS宽度是否大于0,然后添加CSS属性
- 单击禁用的按钮添加 CSS
- 在 Twig Child 中添加 CSS 和 JavaScript
- 更改现有的css属性,并通过删除或添加css元素来使用它
- Ember.js为特定的模型id添加css类
- 我可以用添加css吗!重要的是,只使用jquery
- Regex用于添加CSS类
- 如何在一个表的输入中搜索一组特定的值,而不是另一个表's id(s)值以添加css
- 使用JQuery添加css属性悬停
- 通过程序添加CSS渐变作为背景图像
- 使用JS添加CSS规则
- 如何为Fabric.js中的文本添加CSS属性
- IE7/8未添加css属性'top'动态地作为内联样式
- 通过jquery损坏的旋转木马添加css样式
- Node.js Express应用程序:如果存在cookie,则从服务器端向元素添加CSS类
- 添加css转换时间以使用javascript切换类