0
function loadjscssfile(filename, filetype)
{
if (filetype=="css") 
 {
    var fileref = document.createElement("link");
    fileref.rel = "stylesheet";
    fileref.type = "text/css";
    fileref.href = "filename";
    document.getElementsByTagName("head")[0].appendChild(fileref)
 }
}
loadjscssfile("cssgreen.css", "css") 

and in my html I have

<a href="javascript:loadjscssfile('cssgreen.css','css')">Load green</a>

is there an issue in the html or the js, im fairly new to this so i could be making some mistakes

2 Answers 2

4

Change "filename" to filename. You are sending a hardcoded string as an argument instead of the parameter passed into the function.

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

3 Comments

i did the change but now its loading cssgreen.css instead of cssred.css and won't load cssred.css
<a href="javascript:loadjscssfile('cssred.css','css')">Load red</a> would load cssred.css, provided it is in the same directory as cssgreen.css.
DUH im so dumb i forgot to change that thnx
0

try removing the quotes around "filename" since it's a variable and not a quoted string;

fileref.href = filename;

Comments

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.