Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new element in cheerio

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>')
like image 392
Clite Tailor Avatar asked Apr 02 '17 12:04

Clite Tailor


Video Answer


1 Answers

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
like image 63
André Dion Avatar answered Oct 19 '22 14:10

André Dion