473,848 Members | 1,797 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


Jul 23 '05 #1
4 17241
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
Jul 23 '05 #3
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:

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);

<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>
<form action="" name="aForm">
<input type="button" value="click" onclick="
repRow(document .getElementById ('aRow'));">

Cheers, Rob.
Jul 23 '05 #5

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

Similar topics

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")
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);
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 page in Internet Explorer. Anybody can give solutio for same in firefox browser. function...
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)
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
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 frames.document.body.innerHTML I am only able to change, in the contents of the iframe, the code in...
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 simply remove the the term 'selected' this way:
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;
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 ? Thanks,
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.