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

  • SEARCH
  • Home
  • 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 3226804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:30:00+00:00 2026-05-17T16:30:00+00:00

I am building a javascript widget and i need to add my widget css

  • 0

I am building a javascript widget and i need to add my widget css and js files dynamicly to the client page.

I am doing this for now:

    var css = document.createElement('link');
   css.setAttribute('rel', 'stylesheet');
   css.setAttribute('href', 'css path');
   document.getElementById('test').appendChild(css);
   alert(document.getElementById('test').innerHTML);

But it does not add the element to the dom.
The alert shows correctly.

What i am missing?

EDIT1:

Here is the updated code: (note that this is only a test page).

<html>
    <head>

    </head>
    <body>
        <div id="test">
            test
        </div>

        <script type="text/javascript">


    var css = document.createElement('link');
    css.setAttribute('rel', 'stylesheet');
    css.setAttribute("type", "text/css");
    css.setAttribute('href', 'path');
    var header  = document.getElementsByTagName("head")[0];
    header.appendChild(css);
    alert(header.innerHTML);

        </script>  
    </body>
</html>

header.InnerHtml appears correct but nothing is added to the page.

  • 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-17T16:30:01+00:00Added an answer on May 17, 2026 at 4:30 pm

    have you tried to append the css into the <head> section ?

    var css = document.createElement('link');
       css.setAttribute('rel', 'stylesheet');
       css.setAttribute('href', 'css path');
       document.getElementsByTagName('head')[0].appendChild(css);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an javascript application for which I need to know the html
So I was learning JavaScript/jQuery and building a website as I go along. Now
When building code like this: <script type=text/javascript src=<%=ResolveUrl(~/js/js.js)%>></script> or <input type=image src=<%=ResolveUrl(~/img/submit.png)%> /> Should
I got the following Request Queue implementation from this blog: http://dsgdev.wordpress.com/2006/10/28/building-a-javascript-http-request-queue/ and want to
I've been building a JavaScript and CSS only GUI extension. I followed the instructions
While building a Javascript-heavy web application, what is the best practice for naming CSS
I am building a JavaScript module to add convenience functions to the HTML5 canvas
I'm currently researching the best way to approach building a JavaScript widget someone can
I am building a javascript widget that should load asynchronously. Problem is that there
I am building a web application that uses a lot of Javascript. Now I

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.