Search code examples
javascripthtmlmootools

Setting an attribute without value for a mootools element


I have to re-create the following html element using Mootools

<input type="file" name="file[]" id="file" multiple />

for which I have used the following code

new Element('input', {
    'type': 'file',
    'id': 'file',
    'name': 'file[]',
    'multiple':''
});

Check the fiddle.

The issue is I cannot get the multiple attribute to be set in the element. How can I achieve setting an attribute without value (in this case, multiple) in a mootools element?


Solution

  • multiple is a boolean attribute, so you can pass true as the value:

    $('test').adopt(new Element('input', {
        'type': 'file',
        'id': 'file',
        'name': 'file[]',
        'multiple': true
    }));