Cheerio: Change tag feature

Created on 2 Nov 2017  路  2Comments  路  Source: cheeriojs/cheerio

Feature request: add method to change tag name.

Input:

<ul id="fruits">
  <li class="apple">Apple</li>
  <li class="orange">Orange</li>
  <li class="pear">Pear</li>
</ul>

Code:

$('ul').tag('article');
$('li').tag('section');

Output:

<article id="fruits">
  <section class="apple">Apple</section>
  <section class="orange">Orange</section>
  <section class="pear">Pear</section>
</article>

Most helpful comment

You can just modify the underlying objects.

$('ul').find('li').each((i, item) => (item.tagName = 'section'))

All 2 comments

I second this.

Maybe we could write it?

You can just modify the underlying objects.

$('ul').find('li').each((i, item) => (item.tagName = 'section'))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dandv picture dandv  路  5Comments

gajus picture gajus  路  4Comments

AlbertoElias picture AlbertoElias  路  4Comments

unicrus picture unicrus  路  4Comments

robogeek picture robogeek  路  4Comments