In HTML5, you can add the attribute draggable
to any element -- it works like checked
; it doesn't require a value. If you do want to specify a value (e.g. to make it valid XML), I think the official standard syntax is checked="checked"
, but other things work too (including checked=""
and checked="false"
, confusingly). The standard way to make it ‘false’ is not to include the attribute at all.
<img>
elements seem to be ‘draggable’ by default (even if you don't include a draggable
attribute) – that's why you get the 'ghost' image effect when you drag regular images in web pages. You get this same effect on non-img
elements if you mark them draggable
.
So how do you disable it on img
elements? You can set the property to false in JavaScript. But what about in the HTML?
(From experimenting, I know that draggable="false"
seems to work in Chrome – is that a standard syntax that works everywhere? If so, why doesn't checked="false"
work the same way?)
To set the value of a Boolean attribute, such as disabled , you can specify any value. An empty string or the name of the attribute are recommended values. All that matters is that if the attribute is present at all, regardless of its actual value, its value is considered to be true .
If you want to define your own custom attributes in HTML, you can implement them through data-* format. * can be replaced by any of your names to specify specific data to an element and target it in CSS, JavaScript, or jQuery.
A Boolean attribute is an attribute that can only be true or false. How does a Boolean attribute work? According to the HTML specification: The presence of a boolean attribute on an element represents the “true” value, and the absence of the attribute represents the “false” value.
To add a Boolean attribute: node. setAttribute(attributeName, ''); // example: document. body.
Well, W3C says you're right; "true", "false" and "auto" should work (not to say it will everywhere).
Edit: http://jsfiddle.net/nwellcome/DRSbc/ for to experiment with in different browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With