As far as I know, the actual order of properties of the HTML element is open to interpretation by the browser, so there is no reliable way to determine if you are dealing with <input type="radio" name="Q_209" value="A" checked> or <input checked="true" name="Q_209" value="A" type="radio">
But you can get all the properties and values ββof an element using the for ... in operator:
var foo = document.getElementById('form_id')['Q_209']; var foo_properties = []; for (var prop in foo) {
This means that you can compare the properties found in the element with a subset of the properties that you really need (specific to that particular tag or the larger "html" property universe) to get the "html state" of the element and be able to restore it or string representation.
var input_foo = document.getElementById('form_id')['Q_209']; var awesome_properties = {'type':'','name':'','value':'','checked':''}; var tag = '<input '; var properties = ''; for (var prop in foo) { if (prop in awesome_properties) { properties += ' '+prop+'="'+foo[prop]+'"'; } } tag += properties; tag += '>'; window.alert(tag);
source share