3

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;

2
  • Search for document.stylesheets. There are lots of examples of doing different things with it. 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') Commented Jul 15, 2016 at 21:22

4 Answers 4

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>');
Sign up to request clarification or add additional context in comments.

Comments

1

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>

1 Comment

That only affects the elements currently on the page. If you add new elements dynamically, or change classes, they'll use the style from the CSS.
1

You can do that by using simple jquery.

$('.icon-rollover-color').css('color','red')

Comments

0

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-command:

$(body).append('<style type="text/css">.icon-rollover-color {color:#333!important;}</style>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.