Home / Blog

As I'm working on the new interface of MyOwnDB based on YUI, I have discovered 2 subtle differences between IE and FF when creating nodes with YUI 3.

1. You can't change attribute values of INPUT nodes created from a template using the long closing node syntax

Update: IE is actually doing the right thing, as the input tag does not accept a closing tag as defined by the W3C .

By long syntax, I mean closing a tag with an explicit closing tag:

1<input name="answer"></input>

as opposed to the short syntax:

1<input name="answer" />

If you create an input node with YUI3 based on the long syntax with IE, you won't be able to set attribute values:

1template = '<input name="myfile" type="file"></input>';
2var fileField = Y.Node.create(template);
3fileField.setAttrs({id: 'id453'}); fileField.getAttribute('id'); // => ""

The solution is to use the short syntax to close your tag:

1template = '<input name="myfile" type="file"/>';

Note that this is only for input nodes. Divs are workling fine with the long syntax:

1template = '<div name="divname"></div>';
2 var div = Y.Node.create(template);
3 div.setAttrs({id: 'id453'}); div.getAttribute('id'); // => "id453"

2. With IE, you can't set the type of an input node to "file"

This code will generate a file field with FF, but a text field with IE:

1template = '<input name="myfile"/>'
2var fileField = Y.Node.create(template); fileField.setAttrs({type: 'file'});

If you want to make it work with IE, you have to make your template include the type attribute:

1template = '<input type="file" name="myfile"/>'

I've put a demo page for those interesting in the code, with a YUI console.

I'm available for hire 

If you're looking for someone to temporarily join your IT team, or if you need help to put IT to work in your company, I'm ready to help. Contact me now !

Mon Tue Wed Thu Fri Sat Sun
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31