0

I want css path in the head section of an HTMl page, the path should come through an external JS file as I want to add multiple no. of css.

0

1 Answer 1

2
function addCSS() {
        var headtg = document.getElementsByTagName('head')[0];
        if (!headtg) {
            return;
        }
        var linktg = document.createElement('link');
        linktg.type = 'text/css';
        linktg.rel = 'stylesheet';
        linktg.href = 'CSS/RoundCorners.css';
        linktg.title = 'Rounded Corners';
        headtg.appendChild(linktg);
    }

Source: http://www.devcurry.com/2009/07/how-to-add-css-link-programmatically.html

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

2 Comments

Thanks a lot :) ... Is there any way to use multiple css so I can change the theme. Actually I was looking for the theme changes through css based JS but I stuck on the 1st step which is now solved as u help me...Thank you once again.
@amolD You'd have to change an existing link element rather than append a new one. CoDe ADDict has already posted a link for switching stylesheets cssnewbie.com/simple-jquery-stylesheet-switcher

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.