Undocumented attribs property safe to use?
See original GitHub issueI was looking for a way to move all of one element’s attributes to another element and noticed the attribs
property on cheerio elements which seemed to be exactly what I needed but it’s not documented anywhere that I could see. It is however used in the example in htmlparser2’s readme so I’m wondering if this property is safe to use of if there’s a better way getting at all attributes.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Undocumented classdef attributes
If true , then such properties can be accessed using any case. For example, if the property is called myProp , then it...
Read more >Landlords and Undocumented Tenants: An Overview
By applying the same requisites to each applicant, a landlord can avoid renting to anyone – not just undocumented persons – who could...
Read more >c# - Why is the attribute target 'typevar' undocumented?
Actually, typevar attribute target is documented, but it seems that only in the standardized C# 2.0 Language Specification: ...
Read more >California And Illegal Immigrant Tenant Rights - ADHI Schools
Illegal immigrants live somewhere and with California's notoriously high prices, renting is the only option for many. This raises questions for the landlord....
Read more >5 Rights of Undocumented Immigrants | Clearwater Law Group
The Fifth Amendment, for example, states that “No person shall be deprived of life, liberty, or property, without due process of law.” And...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To clarify on that unfortunately cryptic closure message, it would appear the TypeScript type definitions show an
attr()
method that can be invoked without any arguments to return a simple object map of key-value pairs:https://github.com/cheeriojs/cheerio/blob/a3363012de3ddf4dafe91e89864d8feca9d28722/types/index.d.ts#L18
As shown in tests also:
https://github.com/cheeriojs/cheerio/blob/a3363012de3ddf4dafe91e89864d8feca9d28722/test/api/attributes.js#L16-L20
I’m finding that currently
.attr('value')
and.attribs.value
are returning two different things. Not sure if this is the right place to put this, but I found this thread while trying to find some context for this situation. I’m hoping this will help someone else with the same confusion in the future..attr('value')
returns ‘on’ while.attribs.value
returns undefined. If you’re looking for the ‘real’value
attribute,.attribs.value
seems to give the most accurate to me at the moment for what it’s worth.Again, not necessarily reporting a bug, just hoping to help some future person figure out how to get the [literal] HTML attribute value with cheerio.
[Edit: To be clear, I’m not talking about using
$node.val()
..va()
does a lot of fancy logic to get what a human might think of as the ‘value’ of the node. See #451 talking about that a bit more. Here, I’m talking about the literal value of thevalue
attribute.]