how to link css and javascript code example

Example 1: how to link javascript to html and css

# Javascript
<script src="[file_name].js"></script>

# CSS
<link rel = "stylesheet" type="text/css" href = "style.css" />

Example 2: add css style sheet with javascript

<head>

<script>
function myFunction() {
  var x = document.createElement("LINK");
  x.setAttribute("rel", "stylesheet");
  x.setAttribute("type", "text/css");
  x.setAttribute("href", "styles.css");
  document.head.appendChild(x);
}
myFunction()
</script>

</head>

Tags:

Html Example