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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Weston C

    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.create Element("a");
    anchor
    undefined

    but:

    var anchor = document.create Element("p");
    anchor
    [object HTMLParagraphEl ement]

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

    var anchor = document.create Element("rant") ;
    anchor
    [object HTMLUnknownElem ent]

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

    Thanks,

    Weston

    ~==~

    weston8[at]cann8central.or g
    (remove eights to email me)

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

    #2
    Re: document.create Element('a') doesn't work?

    Here is how I create a new anchor that has an image tag:

    //create the anchor node
    myA=document.cr eateElement("A" );
    url = "javascript:ale rt(" + "hi" + ");";
    myA.setAttribut e("href",url) ;
    //create the image node
    url = url_path + "images/del.gif";
    myImg=document. createElement(" IMG");
    myImg.setAttrib ute("src",url);
    myImg.setAttrib ute("width","16 ");
    myImg.setAttrib ute("height","1 6");
    myImg.setAttrib ute("border","0 ");
    myImg.setAttrib ute("alt","Say Hi");
    // Appends the image node to the anchor
    myA.appendChild (myImg);

    Hope that helps,

    Mike

    Weston C wrote:
    [color=blue]
    > 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.create Element("a");
    > anchor
    > undefined
    >
    > but:
    >
    > var anchor = document.create Element("p");
    > anchor
    > [object HTMLParagraphEl ement]
    >
    > Hmmmm. I tried it on a bunch of other elements, including some that
    > don't exist:
    >
    > var anchor = document.create Element("rant") ;
    > anchor
    > [object HTMLUnknownElem ent]
    >
    > So great. I can create a "rant" tag, but an anchor tag is right out?
    >
    > Thanks,
    >
    > Weston
    >
    > ~==~
    > http://weston.canncentral.org/
    > weston8[at]cann8central.or g
    > (remove eights to email me)
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]

    Comment

    Working...