The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Programming Fundamentals" Dec 02 - 2:00 PM Eastern

How to add an external CSS file to a page with Javascript

  • # September 18, 2012 at 4:43 pm

    I’m wondering how it would be done to have an input field where you can paste a link to an external stylesheet from anywhere, and click a submit button and have that stylesheet be applied to the page it’s on, very similar to how you can do on where you can add in your own external stylesheet. Any help would be appreciated. Thanks!

    # September 18, 2012 at 5:04 pm

    This reply has been reported for inappropriate content.

    you could use the “append()” function in jquery to add it to the element…


    $('button#addCss').on('click', function() {
    var uri = $('input#cssUri').val();
    # September 18, 2012 at 5:25 pm

    Cool, I’ll have to give that a try. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed