Dup Ver Goto 📝

modifying-css-href

PT2/lang/html/experiments does not exist
To
37 lines, 102 words, 1024 chars Page 'modifying-css-href' does not exist.

If you use Javascript to change the href of a <link rel="stylesheet"/> then the browser's rendering updates to the new stylesheet.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="a.css"/>
  <title>Document</title>
  <script>
    window.q = (x,y=document) => y.querySelector(x)
    window.qq = (x,y=document) => Array.from(y.querySelectorAll(x))
    const { log } = console

    window.addEventListener("load",_ => {
      window.addEventListener("click", _ => {
        const link = q("link")
        const href = link.getAttribute("href")
        console.log({href,link})
        if( href.length == 0 ) return;
        if( href[0] == "/" ) {
          log(`abs {href}`)
          return
        }
        const nhref = "a/"+href
        link.setAttribute("href",nhref)
      })
    })
  </script>
</head>
<body>

</body>
</html>