Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Getting the `value` attribute of a `<data>` element returned undefined #40

Closed
wants to merge 3 commits into from

3 participants

François Robichet Dustin Diaz Rod Vagg
François Robichet

No description provided.

Dustin Diaz
Owner
ded commented

this more than likely happens on all HTML5 elements.. :/

François Robichet

The spec allow the value attribute only on <li> in <ol>s and <data>.
I have fix my problem on the <data> by doing this because bonzo doesn't check the case sensitivity on specialAttributes : $('data').attr('Value')

Rod Vagg
Collaborator

@Calvein can you write a test or two for it? Just fiddling in Chrome I can see that (<data>).value gives undefined while (<data>).getAttribute('value') gives the attribute value which is where attr() is tripping up for you but <li> seems to work OK wtih just .value (or ['value']). Would be good to see it across browsers.
Would also be good to fix the case sensitivity thing too, perhaps a toLowerCase() rather than fixing the regex cause I think the spec wants lower case attribute keys anyway?

François Robichet

In IE8 li.value or li['value'] returns a boolean not the correct value.
For the case sensitivity issue, we may just add an i at the end of the specialAttributes variable: /^checked|value|selected$/i

I'll do the test later :)

Dustin Diaz
Owner

hey there @Calvein — i'm going through some old requests, if you'd like this one in, would you mind isolating your edits to src/bonzo.js and of course, keep your added tests? as it stands it conflicts with master. cc @rvagg

François Robichet

I think it would be better to wait for the <data> element to be in the spec (http://dev.w3.org/html5/spec/the-data-element.html) and not only in the whatwg (http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-data-element), I'm not sure if it will stay because of the come back of the <time> element.

Dustin Diaz ded closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 1, 2011
  1. François Robichet
Commits on Nov 2, 2011
  1. François Robichet
Commits on Nov 4, 2011
  1. François Robichet

    Add test for data attribute

    Calvein authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 1 deletion.
  1. +2 −1  bonzo.js
  2. +11 −0 tests/tests.html
3  bonzo.js
View
@@ -16,6 +16,7 @@
, parentNode = 'parentNode'
, query = null
, specialAttributes = /^checked|value|selected$/
+ , valueTags = /data|li/i
, specialTags = /select|fieldset|table|tbody|tfoot|td|tr|colgroup/i
, table = [ '<table>', '</table>', 1 ]
, td = [ '<table><tbody><tr>', '</tr></tbody></table>', 3 ]
@@ -495,7 +496,7 @@
return this
}
return typeof v == 'undefined' ?
- specialAttributes.test(k) ?
+ specialAttributes.test(k) && !(/value/i.test(k) && valueTags.test(el.nodeName)) ?
stateAttributes.test(k) && typeof el[k] == 'string' ?
true : el[k] : (k == 'href' || k =='src') && features.hrefExtended ?
el[getAttribute](k, 2) : el[getAttribute](k) :
11 tests/tests.html
View
@@ -137,6 +137,9 @@
</div>
<div id="styles" style="margin-left:5px;"><div style="float: left;"></div></div>
<div id="callback-styles" data-original="15"></div>
+ <ul id="value-test">
+ <li value="2" ><data value="kittens"></data></li>
+ </ul>
<h1>Bonzo Tests</h1>
<ol id="tests"></ol>
@@ -499,6 +502,14 @@
ok(checkedCount() == 3, 'all checkboxes are checked!')
})
+ test('value attribute', 2, function() {
+ var li = $('#value-test li')
+ , data = $('#value-test data')
+ // @TODO <li> value must be an integer and be inside an <ol>
+ ok(li.attr('value') == 2, 'on li')
+ ok(data.attr('value') == 'kittens', 'on data')
+ })
+
function testCreate(node) {
var e, ex
try { e = $.create('<' + node + '>') } catch (e) {}
Something went wrong with that request. Please try again.