How to apply CSS using User Scripts


Tags: javascript,html,css

Problem :

I have a User Script and I want to apply an external CSS to any web page using that User Script. What possibly could be done for this?

OR

Is it possible that by using JavaScript I can apply an external CSS to any web page?

I am using the following code but it is not working :

  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", "class.css");
  document.getElementsByTagName("head")[0].appendChild(fileref);


Solution :

<link rel="stylesheet" type="text/css" href="class.css" />

    CSS Howto..

    How to fix some issues with printing very basic HTML

    How to fade in and out text and css using jquery

    How to make a 2x2 grid of Div's in CSS?

    How to create menu of overlayed divs?

    How to extend this navigation bar off the page?

    How to properly display content when I resize the window?

    How to arrange input elements to columns or other way to improve form readability

    How to trigger css :hover event on PageLoad

    How can I place two DIVs inside a horizontal fixed header and make all the content vertically align?

    how to create table grid view fix header with long title name using only CSS?

    How can I use Perl to get a list of CSS elements with a color or background color attribute?

    How to grows up a div height with a table that has your rows added dynamically?

    How to know where a CSS error occurred in dynamic content or how to stop the script upon CSS error

    How to overlap a border in CSS in order to create tabs?

    Tricky: In CSS and HTML, how to make a sub DIV go under the container if the container has a z-index of 0?

    How to test css with media queries

    How to obtain non-uniformly scrolling elements and layered “curtain-like” backgrounds on a webpage?

    How to use inline css styling (style=“vertical-alignment:middle;”) in html5 or