0

I have a code that allows to add style with class to head section:

$("<style type='text/css'> .redbold{ color:#f00; font-weight:bold;} </style>").appendTo("head");

If I call this code elsewhere, a new style section is created each time and it looks like this :

<style type="text/css"> .redbold{ color:#f00; font-weight:bold;} </style>
<style type="text/css"> .newclass{ color:black;} </style>

Is this possible to add a new class many times to the style section and do not create new ones each time? Thanks for help

1
  • 1
    Put an id on the style block and then access it. <style id="mystyles">...</style> and then $('#mystyles').append(...) Commented Mar 29, 2018 at 22:14

1 Answer 1

1

Put an id on the style block:

<style id="mystyles">...</style>

then use jQuery to access it:

$('#mystyles').append(...);

Now you can access it as often as you like!

Sign up to request clarification or add additional context in comments.

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.