Javascript: setAttribute() v.s. element.attribute = value to set “name” attribute
My guess (because you didn’t specify the element type) is the element normally does not have a name attribute, so setting the DOM property like that won’t work. For example, setting the name property on an input element will work. Setting it on a div will not. It will work, however, with setAttribute(). jsFiddle.