admin管理员组文章数量:1336576
I have an inline css in my page:
<style id="abc">
.player-holder{
position:relative;
width:100%;
height:40px;
}
.icon-color{
color:#fff;
-webkit-transition: color 0.3s ease-in-out;
transition: color 0.3s ease-in-out;
}
.icon-rollover-color{
color:#fff;
-webkit-transition: color 0.3s ease-in-out;
transition: color 0.3s ease-in-out;
}
</style>
Is it possible to change some values on the fly (using jquery/javascript) so that browser takes change immediately?
Like change:
.icon-rollover-color
to
color:#333;
I have an inline css in my page:
<style id="abc">
.player-holder{
position:relative;
width:100%;
height:40px;
}
.icon-color{
color:#fff;
-webkit-transition: color 0.3s ease-in-out;
transition: color 0.3s ease-in-out;
}
.icon-rollover-color{
color:#fff;
-webkit-transition: color 0.3s ease-in-out;
transition: color 0.3s ease-in-out;
}
</style>
Is it possible to change some values on the fly (using jquery/javascript) so that browser takes change immediately?
Like change:
.icon-rollover-color
to
Share edited Jul 15, 2016 at 21:24 DaniP 38.3k9 gold badges67 silver badges74 bronze badges asked Jul 15, 2016 at 21:16 ToniqToniq 5,02614 gold badges63 silver badges124 bronze badges 2color:#333;
-
Search for
document.stylesheets
. There are lots of examples of doing different things with it. – Barmar Commented Jul 15, 2016 at 21:21 -
1
That's not inline CSS .. that is internal css and you can override that with inline styles setted by Jquery like
$('.icon-rollover-color').css('color','red')
– DaniP Commented Jul 15, 2016 at 21:22
4 Answers
Reset to default 3Yes, you can change inline CSS using the jquery .css() function. See this Fiddle.
$('p').css('color','#00FF00');
If you are dynamically adding elements then I would suggest you write this as a function that is called whenever a new element is added, probably using an event listener, that you can pass your updated style values to as parameters. Something like:
updateDOMStyle('<style>','<value>');
in jquery
<script>
$('.icon-rollover-color').css({
'color': '#333'
});
</script>
in javascript
<script type="text/javascript">
document.getElementByClassName(".icon-rollover-color").style.color="#333"
</script>
You can do that by using simple jquery.
$('.icon-rollover-color').css('color','red')
You, indeed this is possible!
Just add via Javascript or jQuery the following style
-tag on the bottom of your page.
<style type="text/css">
.icon-rollover-color {
color:#333!important;
}
</style>
You can add such codes to the bottom before the body
-tag closes with the append
-mand:
$(body).append('<style type="text/css">.icon-rollover-color {color:#333!important;}</style>');
本文标签: JavascriptjQuery change inline style valuesStack Overflow
版权声明:本文标题:JavascriptjQuery change inline style values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742262050a2442695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论