We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
$.attr('value')
<option>
const cheerio = require('cheerio') const $ = cheerio.load(` <select class="govuk-select" id="colors" name="colors"> <option>Red</option> <option>Green</option> <option>Blue</option> </select> `) console.log($('option:first-child').attr('value'))
'Red' is logged to the console, which is the inner text of the option
undefined should be logged to the console, because the element does not have a value attribute.
undefined
value
This would match how attr works both according to jQuery's documentation and when compared to it's actual behaviour (CodePen).
attr
It looks like this may be caused by this code in the getAttrfunction:
getAttr
cheerio/src/api/attributes.ts
Lines 64 to 67 in 2737898
This was introduced as part of #671 but should probably have only affected the val function as described in the issue it was trying to fix.
val
I'd be open to raising a pull request with a fix if that would be helpful.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Steps to reproduce
Actual result
'Red' is logged to the console, which is the inner text of the option
Expected result
undefined
should be logged to the console, because the element does not have avalue
attribute.This would match how
attr
works both according to jQuery's documentation and when compared to it's actual behaviour (CodePen).Further details
It looks like this may be caused by this code in the
getAttr
function:cheerio/src/api/attributes.ts
Lines 64 to 67 in 2737898
This was introduced as part of #671 but should probably have only affected the
val
function as described in the issue it was trying to fix.I'd be open to raising a pull request with a fix if that would be helpful.
The text was updated successfully, but these errors were encountered: