0

I know it's possible to modify an element's style attribute using JavaScript, but is it possible to modify the global CSS rule itself? Take the following example:

$('div.test').css('display', 'none');

That modifies all pre-existing elements matching:

<div class="test"></div>

If this script were executed while a page was half loaded the DOM tree would not be complete and any matching elements not loaded wouldn't have this styling rule applied. Is there a way to modify the actual div.test rule itself using JavaScript?

By the way, I do have my own solution to this and am not asking for any workarounds. I would just like to know if this in particular is possible since I've never seen it done before.

4
  • Why not just $('.test').hide(); Commented Sep 20, 2014 at 21:57
  • The key is that not all elements are loaded into the DOM yet. Commented Sep 20, 2014 at 21:58
  • That would work if the page were already loaded in memory. Commented Sep 20, 2014 at 21:59
  • $("head").append("<style>.test{display:none}</style>") Commented Sep 20, 2014 at 23:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.