473,396 Members | 1,678 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,396 software developers and data experts.

document.createElement('a') doesn't work?

After noticing some problems with a script, I tried testing various bits
in the squarefree javascript shell (
http://www.squarefree.com/shell/shell.html ) and noticed this:

var anchor = document.createElement("a");
anchor
undefined

but:

var anchor = document.createElement("p");
anchor
[object HTMLParagraphElement]

Hmmmm. I tried it on a bunch of other elements, including some that
don't exist:

var anchor = document.createElement("rant");
anchor
[object HTMLUnknownElement]

So great. I can create a "rant" tag, but an anchor tag is right out?

Thanks,

Weston

~==~
http://weston.canncentral.org/
weston8[at]cann8central.org
(remove eights to email me)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 21648
Here is how I create a new anchor that has an image tag:

//create the anchor node
myA=document.createElement("A");
url = "javascript:alert(" + "hi" + ");";
myA.setAttribute("href",url);
//create the image node
url = url_path + "images/del.gif";
myImg=document.createElement("IMG");
myImg.setAttribute("src",url);
myImg.setAttribute("width","16");
myImg.setAttribute("height","16");
myImg.setAttribute("border","0");
myImg.setAttribute("alt","Say Hi");
// Appends the image node to the anchor
myA.appendChild(myImg);

Hope that helps,

Mike

Weston C wrote:
After noticing some problems with a script, I tried testing various bits
in the squarefree javascript shell (
http://www.squarefree.com/shell/shell.html ) and noticed this:

var anchor = document.createElement("a");
anchor
undefined

but:

var anchor = document.createElement("p");
anchor
[object HTMLParagraphElement]

Hmmmm. I tried it on a bunch of other elements, including some that
don't exist:

var anchor = document.createElement("rant");
anchor
[object HTMLUnknownElement]

So great. I can create a "rant" tag, but an anchor tag is right out?

Thanks,

Weston

~==~
http://weston.canncentral.org/
weston8[at]cann8central.org
(remove eights to email me)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 20 '05 #2

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

Similar topics

4
by: Dante | last post by:
Hello. I have a Javascript that gets data from an XML document and displays it through javascript. The problem is that when I do dcfile.getElementsByTagName("subhead").firstChild.nodeName all I...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
2
by: Andrew Poulos | last post by:
I'm having some trouble getting document.createElement to work with IE 5. Is this because it's unsupported? And, if it is unsupported, is using innerHTML a valid workaround? Andrew Poulos
10
by: andreister | last post by:
He there! I've discovered that the ================================================= document.links('link_id_here').href = "something"; ================================================= is...
6
by: J Williams | last post by:
I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application to create a new HTML document by cloning nodes. The function below is called from the axWebBrowser1_DocumentComplete...
3
by: ezmiller | last post by:
So I have some code that gets the body element of another frame and then tries to dynamically write a table. The code fails when, after creating the table, I try to append it to the document. I...
1
by: Kobi.Pinhasov | last post by:
Hi, I've got several places on page where I'm using the following method document.createElement to create a new element. Is there an event that I can attach to which is fired every time a new...
10
by: webEater | last post by:
Hello, I try the following in Firefox and other modern browsers: window.addEventListener('load', function() { document.title = CSS.getClass('fontSize'); var div = document.createElement('div');...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
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
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,...
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...
0
tracyyun
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...
0
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,...

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.