Get some HTML in a page and place it in a new table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gareth182
    New Member
    • Feb 2008
    • 1

    Get some HTML in a page and place it in a new table

    Hello all.

    I am a complete noob to Javascript, but I do have a good knowledge of HTML & CSS.

    I need someone to tell me if the following issue can be achieved using Javascript, I will explain in as simple terms as possible -

    Consider a webpage that I cannot edit the HTML for, I can only add HTML or style the page with CSS.

    I need to grab a chunk of HTML from that page, and place it inside a new table that's been added by me to that page.

    How is it done?

    Someone mentioned the 'getelementbyid ' 'get elementbytag' script, along with the .appendchild method, but I have no clue how to use these scripts.

    Any help on the situation would be a complete life saver.

    Gareth
  • traineeirishprogrammer
    New Member
    • Jul 2007
    • 24

    #2
    I dont really understand what you are saying. However I do know how javascript works. I will give you the easiest method. Firstly you could simple use
    Code:
     
    var myObject = document.getElementById("ElementsId");
    // You must put it under the element you want to access or else wait until the page loads.
    myObject is now a reference to the actual object on the screen

    So now you have your object.

    Now add the information inside the object.

    Code:
     
    myObject.innerHTML = "HELLO";
    now there is information inside the object and it will show up on you browser.

    innerHTML is both readable and writeable so you can also see whats inside the object also

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

      This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

      Thanks, moderator.

      Comment

      Working...