0
   var mynewhtml = 
                  + '<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"/>'
                  + '<div id="tabs">'
                  +  '<ul>'
                  +  '<li><a href="#tabs-1">Tab 1</a></li>'
                  +  '<li><a href="#tabs-2">Tab 2</a></li>'
                  +  '<li><a href="#tabs-3">Tab 3</a></li>'
                  +  '</ul>'
                  +  '<div id="tabs-1">'
                  + '<p>Lalalala</p>'
                  +  '</div>'
                  +  '<div id="tabs-2">'  
                  +  '</div>'
                  +  '<div id="tabs-3">'
                  +  '</div>'
                  + '</div>'

 $(mynewhtml).appendTo("body");

So I have a wegpage, but I can't alter the html, I can only add html via Jquery/javascript. Adding the html isn't a problem, but how can I use an external style sheet to set the style of my newly added html?

Thank you.

3
  • you can write a chrome extension if you are using chrome. Commented Feb 5, 2014 at 12:46
  • Why can you not edit the html but you can edit the javascript? Commented Feb 5, 2014 at 12:47
  • I'm making a userscript. So i can't alter thehtml file itself but I can alter the html via javascript Commented Feb 5, 2014 at 12:56

2 Answers 2

0

Just try this

$('head').append('<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"/>');
Sign up to request clarification or add additional context in comments.

1 Comment

I now have <link rel="stylesheet" type="text/css" href="code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> in my head, but my list stays a normal list while it should be this : jqueryui.com/tabs/#default
0

For detailed explination you can refer this thread as well.

how to add anything in <head> through jquery/javascript?

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.