Web Analytics Made Easy -
StatCounter createelement problem in netscape6 - CodingForum


No announcement yet.

createelement problem in netscape6

  • Filter
  • Time
  • Show
Clear All
new posts

  • createelement problem in netscape6

    I'm trying to run this code

    var LR = document.createElement(id);

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

    Thank you very much

  • #2
    Your usage of methods is incorrect for one:


    Creates an element with tagName of 'someString':

    For example:


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


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

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

      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.