This returns everything inside of the table which it should.
alert($('table[width="100%"][cellspacing="0"][cellpadding="10"][border="0"]:eq(0)').html());
How would 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>
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()
);
This uses the outerHTML
property if it exists, otherwise makes a .clone()
, appends it to a new <div>
(not on the page), and gets the .html()
of the 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);
What do you plan to do with the HTML?
If you want to put it somewhere else in the DOM then:
$('#place-to-put').append($('table[width="100%"][cellspacing="0"][cellpadding="10"][border="0"]:eq(0)'));
精彩评论