DOM fiddling

Some fiddling with the DOM using a function and closure and stuff. In some ways jQuery-like.

by mich

HTML

<div id="container">
    <div id="div_one">This div has text</div>
    <div id="div_two">This div has text as well.</div>
</div>
<button onclick="doRemove()">Remove div_two</button>

JavaScript

var A = function(elemID) {
    var elem = (typeof elemID === 'string') ? document.getElementById(elemID) : elemID;
    return {
        'html': function() {
            if (arguments.length === 0) {
                return elem.innerHTML;
            }
            else if (arguments.length === 1) {
                elem.innerHTML = arguments[0];
                return this;
            }
        },
        'remove': function() {
            elem.parentNode.removeChild(elem);
            return this;
        },
        '
    }
};

function doRemove() {
    alert(A(document.getElementById('div_two')).remove().html());
}