简体   繁体   中英

Manipulating an existing document using node jquery

I'm using node-jquery , and I'd like to use it to modify an existing document - which is all the way from the doctype to closing html tag.

But I'm finding node jquery a little off -

$ = require 'jquery'
$('body').append "<div class='testing'>Hello World</div>"
console.log $("body").html()

Returns:

<div class="testing">Hello World</div> 

Note the lack of a body tag, which in normal jquery would have been required. It's like there's a blank document - which I'm fine with, except appending a full document makes makes jquery crash.

How can $("body").append() work in a document that has no body? Is anyone else using node-jquery? Is it considered stable? How can I use it to manipulate an existing document?

console.log $('body').html() will output the innerHTML of your body tag, which propably only is the newly created div. Try console.log $('body').parent().html()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM