Skip to content

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

@trymeouteh

Description

@trymeouteh

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions