user1062554
user1062554

Reputation: 5

Chrome extensions: how to grab a part of html on the page?

I have a page in active tab. I need to find in this page a table:

<table width="100%" cellspacing="0" cellpadding="0" border="0" class="details">

grab it until next </table>-tag, and use it (to paste it in a new tab, popup, or just in "alert").

Upvotes: 0

Views: 454

Answers (2)

Dominic
Dominic

Reputation: 3473

I wouldn't include jQuery for such an easy task.

var table = document.getElememtsByTagName("table")[0]; //if it is the first or only table, you could change 0 to any other number if the table always is at the same position

or you could give your table an id:

var table = document.getElementById("my-table");

to get the html just call

var foo = table.innerHtml;

Upvotes: 0

abraham
abraham

Reputation: 47833

The easiest would be to use jQuery to select the table and return the HTML. For example $('table').html() will return a string of the <table> markup.

Upvotes: 1

Related Questions