cheerio icon indicating copy to clipboard operation
cheerio copied to clipboard

Remove id, class, style attribute when attribute value is empty

Open trymeouteh opened this issue 1 year ago • 2 comments

For popular attribute such as id, class, and style which must have a value to be relevant are not removed from any tags when they are empty

For example...

let $ = cheerio.load('<p class="my-class">Hello World</p>', { xml: true });

$('p').removeClass('my-class');

console.log($.html());



$ = cheerio.load('<p style="color: red;">Hello World</p>', { xml: true });

$('*').css('color', '');

console.log($.html());

The output I get...

<p class="">Hello World</p>
<p style="">Hello World</p>

The output I expected...

<p>Hello World</p>
<p>Hello World</p>

trymeouteh avatar Feb 01 '25 02:02 trymeouteh

Hey, I can work on fixing this issue. Please give a like if you want my help. thanks

rickyssj2 avatar Feb 12 '25 23:02 rickyssj2

This is the default behaviour (removeClass documentation)

S1NJED avatar Mar 10 '25 05:03 S1NJED