setting data attributes in html not working
See original GitHub issueSetting a data attribute using attr
throws TypeError: Cannot read property 'test' of undefined
.
Example
$('ul').attr('data-url', 'http://www.example.com');
Error Stack
TypeError: Cannot read property 'test' of undefined at Object.$.each (D:\node\frix\lib\html-creator.js:141:39) at exports.each (D:\node\frix\node_modules\cheerio\lib\api\traversing.js:300:24) at HTMLCreator.insertContent (D:\node\frix\lib\html-creator.js:131:12) at HTMLCreator.resolveElements (D:\node\frix\lib\html-creator.js:56:10) at promises.push.access.readElement.then.template (D:\node\frix\lib\html-creator.js:113:23) at tryCallOne (D:\node\frix\node_modules\promise\lib\core.js:37:12) at D:\node\frix\node_modules\promise\lib\core.js:123:15 at flush (D:\node\frix\node_modules\asap\raw.js:50:29) at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
HTML data attribute not changing [duplicate] - Stack Overflow
When I click on Set Data, it should change all paragraph tags with the data attribute 'tag' to 'Complete' but it's not working....
Read more >Using data attributes - Learn web development | MDN
Using data attributes. HTML is designed with extensibility in mind for data that should be associated with a particular element but need not...
Read more >How to Use HTML Data Attributes - DEV Community
Adding a data attribute is easy. Any HTML element can have any number of data attributes added to its opening tag. We simply...
Read more >Why data- attribute sometimes doesn't work?
Why it doesn't work consistently? I've checked rendered html page and all of those links have proper data-item populated.
Read more >HTML data-* Attribute - W3Schools
The attribute name should not contain any uppercase letters, and must be at least one character long after the prefix "data-" · The...
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
I was also tripped up by this. According to the documentation, one would think that setting data attributes is possible with
data
.The snippet for
data()
reads:So I was surprised when
element.data('key', 'value')
doesn’t change the value.@drsnyder even if it says something else in the documentation, it is standard jquery behavoir, took me some time to figure out.