Member Login






Lost Password?
No account yet? Register


 

Who's Online

We have 138 guests online




How to add a CSS Link programmatically using JavaScript PDF Print
(4 votes)
Written by Peyman   
Thursday, 23 July 2009

How to add a CSS Link programmatically using JavaScript

In this post, here’s a piece of JavaScript code that demonstrates how you can programmatically reference a CSS link on a page.

Code
<html xmlns="http://www.w3.org/1999/xhtml">
<
head>

<
title></title>

<
link href="CSS/FloatDes.css" rel="stylesheet"

title="Float layout" type="text/css" />


<
script type="text/javascript">

function
addCSS() {

var headtg = document.getElementsByTagName('head')[0];

if (!headtg) {

return;

}

var linktg = document.createElement('link');

linktg.type = 'text/css';

linktg.rel = 'stylesheet';

linktg.href = 'CSS/RoundCorners.css';

linktg.title = 'Rounded Corners';

headtg.appendChild(link);

}

</script>
</
head>
<
body onload="addCSS()">

</
body>
</
html>
feed3 Comments
Amir.Mansoury
March 21, 2010
89.165.51.175
Votes: +0

good

report abuse
vote down
vote up
viperking
August 17, 2009
121.28.41.52
Votes: +1

good

report abuse
vote down
vote up
admin
July 23, 2009
83.147.253.154
Votes: +1

good job!

report abuse
vote down
vote up

Write comment
 
  smaller | bigger
 

security image
Write the displayed characters


busy