Passing an object of attributes to document.createElement() as the second argument


Internet Explorer supports:




I think extending setAttribute is the best solution to the original stated problem when weighing the various points made above. It removes the concerns about forward/backward compatibility of createElement; it avoids the discussion of properties vs. attributes; it accomplishes the goal of reducing the number of repetitions of el.setAttribute following the el = document.createElement() line from N to 1; and it should be very intuitive to anyone who is already familiar with the two argument version of setAttribute('key', 'value'). Iā€™d also feel comfortable speculating that it would be easier for vendors to implement. Win, win, win?