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

color:#333;

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 2
  • 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
Add a ment  | 

4 Answers 4

Reset to default 3

Yes, 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