7

What is the best way to create a new element in cheerio?

May be:

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

or

$('li', '<li>bla, bla, bla, ...</li>')
Clite Tailor
  • 438
  • 5
  • 14

1 Answers1

8

Neither load nor the context string actually create HTML. They serve as a starting point for creating a virtual DOM.

Refer to the Manipulation section in the documentation for methods of injecting into the DOM. Namely, the following methods are provided for injection:

  • append
  • appendTo
  • prepend
  • prependTo
  • after
  • insertAfter
  • before
  • insertBefore
  • replaceWith
  • html
  • wrap
Jirik
  • 1,435
  • 11
  • 18
André Dion
  • 21,269
  • 7
  • 56
  • 60