Tuesday 23 May 2017

cannot manipulate dom object after nodejs require statement

I am trying to learn nodejs and I cannot manipulate DOM object after using the require statement in server.js file. However, it works fine without it. When I click on the paragraph in the browser it would not change. Does anyone know why?

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
    </script>
</head>
<body>
    <p id="demo">Click me to change my HTML content (innerHTML)</p>

    <script src="server.js"></script>
</body>
</html>

server.js

var config = require('./config');

document.addEventListener('DOMContentLoaded', function() {
    $("#demo").click(function () {
        document.getElementById("demo").innerHTML = "Paragraph changed!";
    })
});



via tuyenle

No comments:

Post a Comment