3

is there a way to get the outerHTML of the element TABLE using ID attributes?

Example HTML:

<html>
   <head></head>
     <body>
       <table id="mytable">
           <tr>
               <td>Some Data</td>
           </tr>
       </table>
     </body>
</html>
Onimax
  • 107
  • 4
  • 11
  • just edited the sample html above. :) – Onimax Oct 22 '13 at 03:22
  • Possible duplicate of http://stackoverflow.com/questions/5744207/jquery-outer-html – 3dgoo Oct 22 '13 at 03:24
  • I will remodify the question again.. but I guess this sample answered my question enough. – Onimax Oct 22 '13 at 03:32
  • you don't need to change your question. In the future, before you ask a question, use the search to see if your question has already been asked. Search for `get outer html jquery` in Stack Overflow and you will find great answers to your question. – 3dgoo Oct 22 '13 at 03:41
  • i guess i mixed up the question to the answers im looking for.. but i have posted another question which is very clear to my problem.. those who have answered this question is really a great help tho. – Onimax Oct 22 '13 at 04:03
  • this should be the question: [link](http://stackoverflow.com/questions/19508708/conditional-statement-that-check-the-table-id-asp-xml-dom) – Onimax Oct 22 '13 at 04:05

1 Answers1

1

without jquery

document.getElementById('mytable').outerHTML

like

<html>
    <head></head>
    <table id="mytable">
        <tr>
            <td>Some Data</td>
        </tr>
    </table>
    <script>
        var html = document.getElementById('mytable').outerHTML;
        alert(html)
    </script>
</html>

Demo: Plunker

jQuery does not have a method to fetch the outHTML of an element, so again you need to get hold of the dom element reference

$('#mytable')[0].outerHTML

Demo: Plunker

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • or how about DOM? like getting the table via ID? – Onimax Oct 22 '13 at 03:19
  • i have this html stored on the variable and im trying to create a conditional statement that looks on the table id.. i have the sample code here to show you how it is work.. it is written in ASP. html is stored on variable `responseText` For Each table In HTMLDoc.getElementsByTagName("TABLE") If table.className = "results" Then tablestr = table.outerHTML Session("isEmpty") = false End If Next – Onimax Oct 22 '13 at 03:28
  • is there a way to create a conditional statement like this? this code is filtered through className identifier. how about through its ID? – Onimax Oct 22 '13 at 03:30