-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I remove/replace an attribute? #825
Comments
You likely want to use Cheerio for this — the relevant functions are removeAttr and attr. |
@fb55 since Cheerio's release isn't out yet, are there any options available for this today? |
Just use jsdom |
@ivanjeremic I've had issues with jsdom that I don't experience with htmlparser2. Namely the ability to add/update Angular attributes like |
This functionality is available in Cheerio. The unavailability of new loading methods shouldn't make Cheerio less useful. |
Their general stance is that if it's not supported in the browser, they're not going to implement it. That's why that issue was closed without comment.
@fb55 Yes, and it works great, but ESM support is critical for us. And according to these two issues, that hasn't been released: cheeriojs/cheerio#3098, cheeriojs/cheerio#2774 Any chance the 1.0 release will make it out soon? I'd love to be able to use it. |
I'm not 100% sure this doesn't come with any caveats, but I have been removing/replacing attributes like this. import { cloneNode } from 'domhandler'
import * as domutils from 'domutils'
const html = '<form></form>'
const dom = parseDocument(html).children
domutils.findAll(el => el.name === 'form', dom)
.map(el => {
const cloned = cloneNode(el, true)
cloned.attribs.action = '/submit-form'
cloned.attribs.method = 'post'
domutils.replaceElement(el, cloned)
}) EDIT: |
Is there any API for removing/replacing an attribute? If not how would I do it with domutils?
The text was updated successfully, but these errors were encountered: