0

I have a website that I would like to present different styles for evaluation by having users click on a link(s) where an according proposed style gets loaded. How can I dynamically reload .css files?

2 Answers 2

1

Using javascript you should be able to manipulate the css elements (such as document.createElement("style"); and then filling it with what you need and appending it to the page. Replacing that element will change the css that the page is styled with. However, if you are trying to switch between linked .css files, it may not work dynamically because it could require a page refresh.

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

Comments

0

This did the trick!

<script type="text/javascript">
    function loadjscssfile(filename) {
            var fileref = document.createElement("link")
            fileref.setAttribute("rel", "stylesheet")
            fileref.setAttribute("type", "text/css")
            fileref.setAttribute("href", filename)
        }
        if (typeof fileref != "undefined")
            document.getElementsByTagName("head")[0].appendChild(fileref)
    }    
</script>

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.