Click to See Complete Forum and Search --> : Help with regular expressions and <tbody>
sushi
10-09-2008, 09:35 AM
hello guys,
i have this variable with a full html page code in it and in the body there are 2 <tbody> tags . How can I get whatever it's inside the <tbody> tags?
I'm using coldfusion.
any help is appreciated,
sushi.
sstalder
10-09-2008, 02:04 PM
What do you want to get, the code / text?
Here is an example with how to get the HTML via javascript, no regexp needed:
<script type="text/javascript">
function getCode()
{
// Get the first (index: 0) tbody element in the table called "myTable"
var tBodyHTML = document.getElementById('myTable').getElementsByTagName('tbody')[0].innerHTML;
alert(tBodyHTML);
}
window.onload = getCode;
</script>
<table align="left" id="myTable">
<thead>
<tr>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
</tr>
</tfoot>
</table>
felgall
10-09-2008, 04:30 PM
What do you want to get, the code / text?
Here is an example with how to get the HTML via javascript, no regexp needed:
<script type="text/javascript">
function getCode()
{
// Get the first (index: 0) tbody element in the table called "myTable"
var tBodyHTML = document.getElementById('myTable').getElementsByTagName('tbody')[0].innerHTML;
alert(tBodyHTML);
}
window.onload = getCode;
</script>
<table align="left" id="myTable">
<thead>
<tr>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
</tr>
</tfoot>
</table>
The <tfoot> is in an invalid location in that example. It must come before the tbody.
Also IE doesn't allow you to use innerHTML with parts of a table.
sstalder
10-09-2008, 05:33 PM
So did you reply only to begin some sort of argument over a simple example I gave or actually help out this guy?
And I don't know what version of IE you are referring to but IE 6 and 7 both work fine for me with this code.
Also IE doesn't allow you to use innerHTML with parts of a table.You can read, but not write.
So did you reply only to begin some sort of argument over a simple example I gave or actually help out this guy?It's not an argument, merely a correction. Writing tables correctly is very important when you work with the DOM.
http://www.w3.org/TR/html401/struct/tables.html#h-11.2.3