Helpful Information
 
 
Category: DOM and JSON scripting
createelement problem in netscape6

Hi,
I'm trying to run this code


var LR = document.createElement(id);
alert(document.getelementbyid(id));

the second line is not working. What is the problem ?

Thank you very much

Your usage of methods is incorrect for one:

document.createElement('someString')

Creates an element with tagName of 'someString':

For example:

document.createElement('img')

Effectively creates a <img/> tag with no set attributes.

To set any attribute, you should do something like this for example:

var image = document.createElement('img');
image.setAttribute('src', 'myimage.gif');
image.setAttribute('width', '100');
image.setAttribute('height', '50');
image.setAttribute('alt', 'alternate text');

That effectively creates:
<img src="myimage.gif" width="100" height="50" alt="alternate text"/>

But it doesn't exist anywhere inside the document, just as an HTMLImageElement object in Javascript. To add this to the document, you will need to make use of some sort of insertion method, the most common being appendChild():

image = document.body.appendChild(image);

The image is now the lastChild of the html document's body, and the variable image refers to the live node in the document structure now.

Kind of make sense? :)
(Also going to move this to the DOM Scripting forum, slightly more appropriate...)

if just need rendered outside document, like alert, maybe can ignore name attribute of element (or maybe not ???)
i tried with this

----code
<a href="javascript:alertme()">alert me</a>
<script>
function alertme(){
var LR = document.createElement('x').y='Hey You!'
alert(LR)
}
</script>
-----endcode

I thought:
"x" is not html tag element and "y" is not atributte element of "x", but for alert no need to append as html tag, tried at IE6 and NN6 working find, also i tried for status-bar, but NN6 can't work...????, anyone can find out this problem ? PLz correct if anything wrong, i learn programming just from book and internet. Thx.










privacy (GDPR)