ruanmer / insert-nodes

Insert elements into target by passing an object of nodes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Insert elements into target by passing an object of nodes

This example:

$(function () {
    var nodes = [
        {
            element: 'form', 
            html: [
                {
                    element: 'input',
                    attr: {
                        type: 'text',
                        name: 'foo',
                        id: 'foo',
                        placeholder: 'foo',
                        val: 'value'
                    }
                },
                {
                    element: 'button',
                    type: 'submit',
                    attr: {
                        text: 'Call Alert',
                        click: function () {
                            alert('alert');
                        }
                    },
                },
            ]
        }
    ];
    
    $('body').insertNodes(nodes);
});

Insert this HTML into body tag:

    <form><input type="text" name="foo" id="foo" placeholder="foo"><button type="submit">Call Alert</button></form>

Useful for?!

Don't know =) You tell me. Fork it if you have any improvement idea.

About

Insert elements into target by passing an object of nodes


Languages

Language:JavaScript 100.0%