demavend demavend - 4 years ago 89
HTML Question

Is there a way to include css files through variable in HTML file?

I'm looking for a way to include css files through variable in html file.

<html>
<head>
<!-- variable = "/css/style.css" -->
<link rel="stylesheet" href=variable>
<link rel="stylesheet" href=variable>
</head>
<body>
<!-- Do anything -->
</body>
</html>

Answer Source

You can do that using JavaScript ... Create a JavaScript variable and according to its value change the value of the href attribute something like this

<link href="url.css" id="selector" type="text/css" />
<script> var variable = 'value`;  </script>
...
<script>
if (variable) {  // Or whatever you need to do
  document.getElementById("#selector").href = "another.css";
}
</script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download