Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I just wrote this code and when I tested it, the javascript wouldn't work. I have javascript enabled and I tried with a different code and it worked. I think there's maybe a bug but I can't see it.

<!DOCTYPE html>
<html>
<body>
    <p id=“id”>Some Text</p>
    <script>
        document.getElementById(“id”).innerHTML=“Different Text”;
    </script>
</body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

You are using smart quotes (“”) instead of normal quotes (""). Replace the quotes and it will work.

<p id="id">Some Text</p>
<script>
    document.getElementById("id").innerHTML="Different Text";
</script>

Perhaps this is because you are using a word processor, not an IDE?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...