0

Is my browser using cached JavaScript, or should this code be able to run as is?

Initially, I had declared a variable named p1:

var p1 = document.getElementById('p1');

I wanted to put this variable in different places to play around with scope in JavaScript, but the code still executes. I have changed browsers and cleared the cache.

<!DOCTYPE html>
<html>
    <head>
        <script>
        function changePar(){
            p1.innerHTML = "It worked!";
            p1.style.color = "blue";
        }
        </script>
    </head>
    <body>
        <p id="p1">Paragraph One</p>
        <button onclick="changePar()">Click Me!</button>
    </body>
</html>
Adam Patterson
  • 958
  • 7
  • 13

0 Answers0