Can I use jQuery with Node.js?

前端 未结 20 1642
清歌不尽
清歌不尽 2020-11-22 05:42

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

20条回答
  •  不思量自难忘°
    2020-11-22 06:08

    WARNING

    This solution, as mentioned by Golo Roden is not correct. It is just a quick fix to help people to have their actual jQuery code running using a Node app structure, but it's not Node philosophy because the jQuery is still running on the client side instead of on the server side. I'm sorry for giving a wrong answer.


    You can also render Jade with node and put your jQuery code inside. Here is the code of the jade file:

    !!! 5
    html(lang="en")
      head
        title Holamundo!
        script(type='text/javascript', src='http://code.jquery.com/jquery-1.9.1.js')
      body
        h1#headTitle Hello, World
        p#content This is an example of Jade.
        script
          $('#headTitle').click(function() {
            $(this).hide();
          });
          $('#content').click(function() {
            $(this).hide();
          });
    

提交回复
热议问题