In article <jrdgfr$pmp$>,
"Jukka K. Korpela" <> wrote:
> 2012-06-14 22:31, Tim Streater wrote:
>
> > I just wasted an hour until I remembered that the dataset variables in
> > HTML5 have to be integers. Anyone know why there is this limitation?
>
> There is no such limitation.
OK, I looked here:
<http://www.w3.org/TR/2009/WD-html5-20090423/dom.html>
(whether this is the correct place I know not) and there is no explicit
mention of types, although I guess, as you say below, that values have
to be settable via HTML, which would preclude boolean values.
> > if (ptr.dataset.myflag==true) return;
> >
> > was not being executed even though myflag had been set to true earlier
>
> You cannot set it to the truth value true in HTML markup. If you have
>
> <li data-myflag="true">
>
> or, equivalently,
>
> <li data-myflag=true>
>
> then you are setting the value to the string "true". You can check this
> in JavaScript by displaying typeof(ptr.dataset.myflag).
>
> And in JavaScript, even the "==" operator, which tests for an
> equality-like relation, does not treat the truth value true and the
> string value "true" as identical.
>
> So you would need to test ptr.dataset.myflag == "true" or
> ptr.dataset.myflag === "true".
>
> As a different issue, such a way of accessing data-* variables is not
> supported by all browsers (see http://caniuse.com/dataset), so it would
> be safer to test for
>
> ptr.getAttribute('data-myflag') === "true"
In fact I'm not setting it in HTML. I'm setting it in JavaScript, as in:
ptr.dataset.myflag = true;
(but now using integers instead, as I mentioned). So I wonder what that
actually sets it to.
I control which browser gets used (Safari, in this case).
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689