#12323 closed bug (worksforme)
elment.attr('data-*, value) does not update element.dataset if data-* key does not exist
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | attributes | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
simple example:
html:
<div id="d" data-k1="v1"> </div>
javascript:
/* correctly sets $('#d').context.dataset.k1 to 'some value' */
$('#d').attr('data-k1', 'some value');
/* $('#d').context.dataset.k2 is undefined */
$('#d').attr('data-k2', 'some other value');
/* $('#d').context.dataset.k2 is set to 'some other value' */
$('#id').context.setAttribute('data-k2', 'some other value');
I was able to work around the issue by using the native setAttribute method.
I was also able to work around this by setting the dataset property manually, but according to the w3c spec, it's supposed to be a read only property. None of the browsers tested enforce this however.
Browsers tested on: Firefox, Chrome and Opera (ie doesn't support the dataset property)
Change History (5)
comment:1 follow-up: 2 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
Replying to rwaldron:
jQuery's
data()
functionality existed long beforedataset
and has it's own semantic behaviour to adhere to, and it's expected to be fast. A DOM operation will slow it down tremendously (as well as having no effect in browsers that don't support it).
I understand what you are saying about the data() functionality, and I use the data() functionality as well, and it is a nice. I like it, but it is not the optimal solution for what I need to do, nor does it really have anything to do with this topic.
I'm talking about the attr() function, which does work as expected if an attribute is already set for the DOM node, as noted above. Which would imply that attr() is already modifying the DOM.
I was reporting it to be a good citizen, but it is good to know you have no intentions of fixing it, so I'll just make it policy to not use the attr method and instead use the native setAttribute method on the dom node, no big deal to me, I didn't bang my head on the issue that long.
comment:3 Changed 10 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
comment:4 Changed 10 years ago by
Component: | unfiled → attributes |
---|---|
Resolution: | → worksforme |
Status: | reopened → closed |
Works for me: http://jsfiddle.net/LxmLh/
Tested in Chrome and Firefox.
comment:5 Changed 10 years ago by
That's what I get for closing tickets at the tail end of working 12 hours straight... Sorry!
jQuery's
data()
functionality existed long beforedataset
and has it's own semantic behaviour to adhere to, and it's expected to be fast. A DOM operation will slow it down tremendously (as well as having no effect in browsers that don't support it).