在 cheerio 中创建新元素

Create new element in cheerio

在 cheerio 中创建新元素的最佳方法是什么?

可能是:

cheerio.load('<li>something in here!</li>')

$('li', '<li>bla, bla, bla, ...</li>')

load 和上下文字符串都没有实际创建 HTML。它们作为创建虚拟 DOM.

的起点

Refer to the Manipulation section in the documentation 用于注入的方法 DOM。即提供以下方法进行注入:

  • append
  • appendTo
  • prepend
  • prependTo
  • after
  • insertAfter
  • before
  • insertBefore
  • replaceWith
  • html
  • wrap