473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting outerHTML - can this be done?

Using IE 5.5 (sp2) - no other

I have a table that need's to be sorted by single column using javascript.

I have the code to do this but because of the attributes associated with the
<tr> element, when the sorted values are copied back in to the table I want
to replace the entire row not just the inner values!

Any ideas why this doesn't work?

var x = getElementByID( 'myTable'); //
def get's object successfully
alert(x.rows(0) .outerHTML);
// before, shows current content
x.rows(0).outer HTML = "<tr><td>pl ease work</td></tr>"; // Just to test,
but goes no further, no error just bombs out!
alert(x.rows(0) .outerHTML);
// after

thanks

harry
Jul 23 '05 #1
4 17191
sorry didn't realise what mess it would look with comments -

var x = getElementByID( 'myTable');
alert(x.rows(0) .outerHTML);
x.rows(0).outer HTML = "<tr><td>pl ease work</td></tr>";
alert(x.rows(0) .outerHTML); // never gets here
Jul 23 '05 #2
harry wrote:
Any ideas why this doesn't work?


IE doesn't let you set the innerhtml or outerhtml of td's or tr's. You also
can't set the innerhtml of a table. You can only set the outerhtml of the
full table itself.

If you want to manipulate table rows or cells, use DOM methods instead.
Or replace the entire table's outerhtml, which could be very slow.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #3
VK
The Table Object Model cannot be manipulated in such way.

var myTable = getElementById( 'myTable');
var myRow = myTable.insertR ow();
if (myRow != null) {
var myCell = myRow.insertCel l();
myCell.innerHTM L = '<b>It works !!!!!!!!</b>';
}
else {
window.alert('Y ou can not change a data-bound table. You have to change the
data source itself');
}
More of useful reading:
http://msdn.microsoft.com/workshop/a...uildtables.asp

Jul 23 '05 #4
harry wrote:
sorry didn't realise what mess it would look with comments -

var x = getElementByID( 'myTable');
alert(x.rows(0) .outerHTML);
x.rows(0).outer HTML = "<tr><td>pl ease work</td></tr>";
alert(x.rows(0) .outerHTML); // never gets here


Try using the DOM, it looks a but unweildy but it works.
You can replace individual TDs if you want, you can also use
cloneNode to make a copy of an element that contains a
complex set of other elements (much simpler than slabs of
createElement or innerHTML statements).

<script type="text/javascript">
function repRow(oldTR) {
var newTR = document.create Element('tr');
var newTD = document.create Element('td');
var newTX = document.create TextNode('Repla cement text')
newTD.appendChi ld(newTX);
newTR.appendChi ld(newTD);
oldTR.parentNod e.replaceChild( newTR,oldTR);
}
</script>

<table id="myTable" border="1">
<tr><td>Row above</td></tr>
<tr id="aRow"><td>H ere is the current content</td></tr>
<tr><td>Row below</td></tr>
</table>
<form action="" name="aForm">
<input type="button" value="click" onclick="
repRow(document .getElementById ('aRow'));">
</form>

Cheers, Rob.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11256
by: Pai | last post by:
Hello there, I have the following peice of javascript which works with IE but would not work with mozilla. In IE the first for loop is entered but in mozilla i would not enter the for loop any tips / ideas? var tblObj=document.body.getElementsByTagName("TD")
22
2832
by: necromonger | last post by:
Hi, I've got this code that creates a new new row and cell. I then put some text into the cell with innerHTML - works beautifully with Firefox but fails with IE. I guess IE doesn't support this way of doing it, but is there another way of doing it with DOM? newr = document.createElement('tr'); stbl.appendChild(newr);
1
13288
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a alternative for outerHTML property in firefox. I am using th following function to display an image and alternate text behind al images of a weg...
0
1199
by: schapopa | last post by:
I am exporting data to excel using VBScript: Dim sHTML sHTML = document.all.item("DataGrid1").outerhtml Dim oXL Dim oBook Dim oSheet Set oXL = CreateObject("Excel.Application") Set oBook = oXL.Workbooks.Add Set oSheet = oXL.Worksheets(1)
25
2946
by: MeNotHome | last post by:
I am automating the navigation of a website. When I reach the end, it changes to xml. So my axwebbrowser1 has a bunch of xml data in it. So here is what I am trying to do Dim xmlText As String Dim doc As New XmlDocument() Dim myElem As XmlElement
3
2295
by: David Virgil Hobbs | last post by:
I discovered how to write out the inner HTML of the contents of an Iframe; I want to know how to write out the outerHTML of the contents of an Iframe. frames.document.body.innerHTML allows me to read the inner HTML of the contents of an iframe and also allows me to write out the inner HTML of the contents of an iframe. However using...
1
3532
by: cweeks | last post by:
Dev env: VS 2005 C# Express, .Net Framework 2.0 I am trying to programmatically select an item in a listbox on a web page. The first thing I do is go through and de-select any selected items. The OuterHtml field of a selected element in the listbox looks something like this: <OPTION value=* selected>Default item</OPTION> I want to...
1
2592
by: rishabhshrivastava | last post by:
Hey All, I want to get the OuterHtml in a TextBox and I am using following code but I am getting value as "undefined" Please let me know if I am doing anything wrong.. function GetValue() { document.getElementById("txtBox").value = parent.main.document.documentElement.outerhtml ; return document.getElementById("txtBox").value;
2
2680
by: Smugsboy | last post by:
Hi, Got a problem here. I'm trying to create a bookmarklet on IE6, that passes the outerHTML of the body element as a GET param my site. The problem is that for some page (ie mail.yahoo.com) the bookmarklet does not work while for other pages (simpler ones) it does work. Any idea ? Can it be something regarding size of GET param ? ...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.