jQuery jquery更改div类的样式属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19581763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery to change style attribute of a div class
提问by Anurag Sharma
I have a slider class like this and I wan to change the style attribute style="left: 336px"
我有一个这样的滑块类,我想更改样式属性style="left: 336px"
<div id="range-cont">
<div class="slider">
<div class="progress" style="width: 350px;"></div>
<a class="handle" href="#" **style="left: 336px;"**></a>
</div>
<input id="percentage" class="range" type="range" value="14" name="percentage" min="0" max="100">
<p id="percent-label">%</p>
</div>
</div>
I tried
$('.handle').css({'style':'left: 300px'})
but its not working.
Not sure what I am doing wrong here
我试过,
$('.handle').css({'style':'left: 300px'})
但它不工作。不确定我在这里做错了什么
回答by Ganesh D
Just try $('.handle').css('left', '300px');
你试一试 $('.handle').css('left', '300px');
回答by The Code
if you just want to set the style attribute use
如果您只想设置样式属性,请使用
$('.handle').attr('style','left: 300px');
Or you can use css method of jQuery to set only one css style property
或者你可以使用 jQuery 的 css 方法只设置一个 css 样式属性
$('.handle').css('left', '300px');
OR same as key value
OR 与键值相同
$('.handle').css({'left': '300px', position});
回答by Raghuveer
Try with
试试
$('.handle').css({'left': '300px'});
Instead of
代替
$('.handle').css({'style':'left: 300px'})
回答by Дима Попов
$('.handle').css('left', '300px');
$('.handle').css({
left : '300px'
});
$('.handle').attr('style', 'left : 300px');
or use OrnaJS
或使用 OrnaJS
回答by q99
$('.handle').css('left','300px')
try this, identificator first then the value
$('.handle').css('left','300px')
试试这个,先是标识符,然后是值
更多关于这里:
回答by Sridhar R
this helpful for you..
这对你有帮助..
$('.handle').css('left', '300px');
回答by Somnath Kharat
Style is an attribute so css
won't work for it.U can use attr
样式是一个属性,因此css
不适用于它。您可以使用attr
Change:
改变:
$('.handle').css({'style':'left: 300px'});
T0:
时间:
$('.handle').attr('style','left: 300px');//Use `,` Comma instead of `:` colon
回答by Kavya Hanumantharaju
You can't use
$('#Id').attr('style',' color:red');
and
$('#Id').css('padding-left','20%');
at the same time.
You can either use attr
orcss
but both only works when they are used alone.
您不能同时使用
$('#Id').attr('style',' color:red');
和
$('#Id').css('padding-left','20%');
。
您可以使用attr
或css
但两者仅在单独使用时才有效。