I’m trying to create a couple of buttons using jQuery, with commands like this:
$('<button></button>', { type: 'reset', id: 'reset', name: 'reset' })
.text('Reset all fields').appendTo(target);
This works pretty well, except that the buttons are created without the type attribute.
This is what I want:
<button type="reset" id="reset" name="reset">Reset all fields</button>
but I get this:
<button id="reset" name="reset">Reset all fields</button>
i.e. the type="reset" is missing. I’ve tried adding it separately with .attr(), but it doesn’t help. The attribute is simply ignored. What am I missing here?
I’m using jQuery 1.4.4. As noted in comments, this works in the latest jQuery version, but that’s not the one in our system and I don’t know what things might break if we upgrade, so I’d prefer to solve this with the existing version.
Have you considered just doing