td in a function

2

Is it possible to add a td / div / table / iframe within a function?

For example:

function Retorno(){
    <td height="#" width="#" >
        <div id="#" width="#">
            <table width="#">
                <tr>
                    <td >
                        <iframe style="#" src="#" width="#" height="#" >
                        </iframe>
                    </td>
                </tr>
          </table>
       </div>
    </td>   
}

To summarize, I'd like it to be like:

function Retorno(){
    window.self.location.href ="#";
}

Only by determining size, shape, etc.

    
asked by anonymous 30.06.2014 / 17:20

2 answers

4

One possibility is to save this HTML as a template inside a <script> tag. type="text/template" causes content not to be interpreted as JS:

<script id="template-celula" type="text/template">
    <td height="#" width="#" >
        <div id="#" width="#">
            <table width="#">
                <tr>
                    <td >
                        <iframe style="#" src="#" width="#" height="#" >
                        </iframe>
                    </td>
                </tr>
          </table>
       </div>
    </td>   
</script>

<table><tr></tr></table>

<script>
function celula() {
     var html = document.getElementById('template-celula').innerHTML;
     var div = document.createElement('div');
     div.innerHTML = html;
     return div.firstChild.nextSibling;
}
document.getElementsByTagName('tr')[0].appendChild(celula());
</script>

link

    
30.06.2014 / 18:40
2

I recommend using Buildr .

var iFrames = [{
    width: "560",
    height: "315",
    src: "//www.youtube.com/embed/rj6OLq9W6RE",
    frameborder: 0,
    allowfullscreen: true
}];

$div = $("div");

function Retorno() {
    $div.build(function (b) {
        b.table(function () {
            b.each(iFrames, function (idx, it) {
                b.tr(
                b.td(
                b.iframe({
                    width: it.width,
                    height: it.height,
                    src: it.src,
                    frameborder: it.frameborder,
                    allowfullscreen: it.allowfullscreen
                })));
            });
        });
    });
}

Example: link

    
30.06.2014 / 18:21