I would like to return the full html, including the table tag

This returns everything that should be inside the table.

alert($('table[width="100%"][cellspacing="0"][cellpadding="10"][border="0"]:eq(0)').html());

How do I get the HTML inside the table, as well as the actual table tag, in this case

<table width="100%" cellspacing="0" cellpadding="10" border="0">
----html----
</table>
+3
source share
3 answers

See this thread :

Add this extension code:

$.fn.outer = function(val){
    if(val){
        $(val).insertBefore(this);
        $(this).remove();
    }
    else{ return $("<div>").append($(this).clone()).html(); }
}

Then you can do this:

alert(
    $('table[width="100%"][cellspacing="0"][cellpadding="10"][border="0"]:eq(0)')
    .outer()
);
+4
source

This uses the property outerHTMLif it exists, otherwise it does .clone(), adds it to a new one <div>(not on the page) and gets a .html()div.

var table = $('table[width="100%"][cellspacing="0"][cellpadding="10"][border="0"]:eq(0)');

var outerTag = table[0].outerHTML || $('<div/>').append(table.clone()).html();

alert(outerTag);
+3
source

HTML?

DOM, :

$('#place-to-put').append($('table[width="100%"][cellspacing="0"][cellpadding="10"][border="0"]:eq(0)'));
+2

Source: https://habr.com/ru/post/1773854/


All Articles