2

I know cheerio.load() will load the html into the $ as below.

var cheerio = require('cheerio'),
$ = cheerio.load('<ul id = "fruits">...</ul>');

Is there a way I can get the same $ using raw jQuery?

BlueElixir
  • 3,299
  • 8
  • 20
  • 23
  • Do you want use nodejs ? – olexiy86 Mar 12 '17 at 19:20
  • I am only limited to client side for now so I unfortunately cannot use node js. – BlueElixir Mar 12 '17 at 19:22
  • 1
    The value returned from `cheerio.load()` is a reference to the [`jQuery()`](https://api.jquery.com/jQuery/) function, or at least [an equivalent of it](https://github.com/cheeriojs/cheerio#selectors). When used client-side, the jQuery library itself [defines `$` as a global alias](https://api.jquery.com/jQuery/#entry-longdesc). – Jonathan Lonowski Mar 12 '17 at 19:23
  • `$ = $('#fruits'); $.querySelector(your css selector); ` – Jonathan Portorreal Mar 12 '17 at 19:23
  • In this case you can get any element, or tag, or anything use jQuery! – olexiy86 Mar 12 '17 at 19:24
  • Alright, I think I understand now that jQuery is just more verbose than Cheerio. Thanks for the answer guys. – BlueElixir Mar 13 '17 at 00:01
  • Are you trying to work on the current document or on a string of HTML? If the latter, maybe [`parseHTML`](https://api.jquery.com/jQuery.parseHTML/)? – ggorlen Nov 26 '22 at 02:10

0 Answers0