Convert attribute/value pairs of a DOM element into a Javascript object?
<p>Is there a shortcut function that converts a DOM element and its various attribute/value pairs to a corresponding Javascript object?</p>

<p>E.g convert this in the HTML page:</p>

<pre><code>&lt;div id="snack" type="apple" color="red" size="large" quantity=3&gt;&lt;/div&gt;
</code></pre>

<p>to an object in Javascript, as if you had typed:</p>

<pre><code>var obj = {
        id:  "snack"
        type: "apple"
        color: "red"
        size: "large"
        quantity: 3
};
</code></pre>
