Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:04:59+00:00 2026-05-24T01:04:59+00:00

I load css var ss = document.createElement(link); var url = ‘http://site.ru/style.css’; ss.setAttribute(rel, stylesheet); ss.setAttribute(type,

  • 0

I load css

var ss = document.createElement("link");
var url = 'http://site.ru/style.css';
ss.setAttribute("rel", "stylesheet");
ss.setAttribute("type", "text/css");
ss.setAttribute("href", url);
document.getElementsByTagName("head")[0].appendChild(ss);

I want to call function after css loading, but tag link hasn’t onload event, is there a way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:05:00+00:00Added an answer on May 24, 2026 at 1:05 am

    You currently don’t load that css stuff via Ajax, but you could do it. That way, you also have your callback when data transfer has finished. I’m using jQuery in this example to make things short and convinient.

    Be aware: This only works if your javascript & your css files are located on the same domain.

    $.get('http://site.ru/style.css', function( css ) {
        $('<style>', {
            html: css
        }).appendTo( document.head || document.getElementsByTagName( 'head' )[0] );
    });
    

    Simplified vanilla Javascript might look like:

    var req;
    
    try {
        req = new XMLHttpRequest();
    } catch ( e ) {
        req = new ActiveXObject( 'Microsoft.XMLHTTP' ); // there are plenty more
    } finally {
        req.onreadystatechange = function() {
            if( req.readyState === 4 ) {  // simplified/shortened
                var head          = document.head || document.getElementsByTagName('head')[0] || document.documentElement,
                    lnk           = document.createElement('style');
                    lnk.type      = 'text/css';
                    lnk.textContent = lnk.text = req.responseText;
    
                head.insertBefore(lnk, head.firstChild);
            }
        };
    
        req.open('GET', 'http://site.ru/style.css', true);
        req.send(null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[[self mainFrame] loadHTMLString:@<html><body><link href='main.css' rel='stylesheet' type='text/css' /></body></html> baseURL:nil]; I am trying to load a
You can use the URL helper in Code Igniter to load CSS and Javascript
I dynamically load a css stylesheet (with a little help from jQuery) like this:
i'm having problem when i want to load css file with document.write() when i
I want to load some .css files to my Django project but I don't
Is there a way to load external CSS files, like we load JS file
I'm trying to dynamically add a css stylesheet rule using javascript, something like example
I have long known that you can load style rules into a page dynamically
I have a range of animations (see code) that load on document load, i
I'm trying to get lightbox2 working with my site, http://www.therussianfrostfarmers.com/ , however i seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.