473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tables and anchors

Hi

I'm attempting to add a hyperlink to a table cell using javascript.

Here's the code:

var cell = document.getElementById("td1");
var aHref = document.createElement("A");
aHref.innerText = "hello";
aHref.href = "index.htm";
aHref.title = "hello";
aHref.id= "alinkage";
cell.appendChild(aHref);

This works with IE but I can't get it to work with Firefox.

I can see that cell.childNodes is incremented after running this code
but nothing is displayed.

Any tips would be grateful.
Jul 23 '05 #1
4 1101
On 23 Nov 2004 05:53:35 -0800, Hooligan <pj********@bigfoot.com> wrote:

[snip]
var aHref = document.createElement("A");
aHref.innerText = "hello";
[snip]
This works with IE but I can't get it to work with Firefox.
That's because innerText is a proprietary property invented by Microsoft,
and most user agents don't support it.

[snip]
Any tips would be grateful.


var text = document.createTextNode('hello');
aHref.appendChild(text);

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2


Hooligan wrote:

var aHref = document.createElement("A");
aHref.innerText = "hello";


You need to create text node and append that e.g.
aHref.appendChild(document.createTextNode("hello") );
as innerText is not part of the W3C DOM and is not implemented by
Mozilla. However creating and appening text nodes works as well in IE so
there is no need to use innerText above.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41***********************@newsread2.arcor-online.net>...
Hooligan wrote:

var aHref = document.createElement("A");
aHref.innerText = "hello";


You need to create text node and append that e.g.
aHref.appendChild(document.createTextNode("hello") );
as innerText is not part of the W3C DOM and is not implemented by
Mozilla. However creating and appening text nodes works as well in IE so
there is no need to use innerText above.


Thanks for the prompt responses though I solved it when I used
innerHTML (I'd tried earlier with this and failed because of a typo).

createElement is working and is documented at W3C and appears more
appropriate for my needs than createTextNode.
Jul 23 '05 #4
DU
Hooligan wrote:
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41***********************@newsread2.arcor-online.net>...
Hooligan wrote:
var aHref = document.createElement("A");
aHref.innerText = "hello";


You need to create text node and append that e.g.
aHref.appendChild(document.createTextNode("hello") );
as innerText is not part of the W3C DOM and is not implemented by
Mozilla. However creating and appening text nodes works as well in IE so
there is no need to use innerText above.

Thanks for the prompt responses though I solved it when I used
innerHTML (I'd tried earlier with this and failed because of a typo).

createElement is working and is documented at W3C and appears more
appropriate for my needs than createTextNode.


but "hello" is a string, not an HTML element. What Martin replied to you
is correct, best cross-browser and web standards compliant method of
creating a text node.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.3 :)
Jul 23 '05 #5

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

Similar topics

7
by: Ben Wilson | last post by:
To anyone who can help me, you have my thanks in advance. I am implementing a "301 Moved Permanently" redirect in my website due to a change of our domain names. Unfortunately, I am having a...
1
by: Peter Jakobi | last post by:
Hello, I want to place two lines relative to another. The problem is, that these two lines are in different groups. Is there an possibility to set the x and y values of the second line with...
2
by: mlv2312 | last post by:
Hi, I have experienced problems when dealing with nested anchors. I implemented some code to perform highlighting and specific anchors are used for the searched words. The problem is when the...
1
by: mlv2312 | last post by:
Hi, I have experienced problems when dealing with nested anchors. I implemented some code to perform highlighting and specific anchors are used for the searched words. The problem is when the...
2
by: learner | last post by:
Hi, A document has many Anchors. I want to take a particular action only if some particular anchors are clicked. I mean if some anchors are clicked, i want an alert box to pop up with ok and...
21
by: adrian suri | last post by:
Hi just started to experement with styleshhets, and have defined hover a:hover { Color : red; Text-decoration : none; Border-top-width : medium; Border-right-width : medium;
17
by: Crimperman | last post by:
Hi, need some advice on URIs In a dynamic page (perl driven) we list a number of items presented in an hierarchical tree structure. Within that page is a form which allows you to search for...
1
by: Alec MacLean | last post by:
Hi. I'm using VS2005 Pro to work on a website project for my company. The site has several navigation elements, all based on the standard VS2005 navigation components. I have high-level...
3
by: windandwaves | last post by:
does it matter if I write var anchors = document.getElementsByTagName("A"); or var anchors = document.getElementsByTagName("a"); Or is there a better way to catch both <a hrefs and <A...
1
by: Patient Guy | last post by:
I have a "hidden" anchor in the body of a doc. By "hidden," I mean that the contained text of the anchor is indistinguishable from the surrounding text, the text contained by its parent/ancestor...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.