SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Location
    Iran
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    something like an not like getElementById

    Is there any method in javascript that can get an object of element (such as td) when i give a parameter as its id.
    I want to use appendChild method of td object to add an object that i know it's id, but this does not work with getElementById. Is there any method such as getElementById except that it give the exact tag element not the thing that getElementById give.

  2. #2
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by persiangulf View Post
    Is there any method in javascript that can get an object of element (such as td) when i give a parameter as its id.
    I want to use appendChild method of td object to add an object that i know it's id, but this does not work with getElementById. Is there any method such as getElementById except that it give the exact tag element not the thing that getElementById give.
    Try

    var cells = document.getElementsByTagName('td');

    Thanks

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a copy of the element returned by getElementById()
    http://developer.mozilla.org/en/DOM/element.cloneNode
    Code:
    var trg=document.getElementById('td_id');
    var elm_copy=trg.cloneNode(1); //make a deep copy of the element pointed by trg
    table.rowElm.appendChild(elm_copy);

  4. #4
    SitePoint Member
    Join Date
    Sep 2008
    Location
    Iran
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thanks I did it by document.getElementsByTagName

  5. #5
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by persiangulf View Post
    Thanks I did it by document.getElementsByTagName
    Thats gr8!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •