0

Newbie in javascript.

Suppose I have this html

    <html>
    <div id = "div1">
      <table>
       <tr><td>Name</td></tr>
       <tr><td>Password</td></tr>
      </table>
    </div>
    <div id = "div2">
      <input name="place" value=""/>
      <input name="place" value=""/>
    </div>
    </html>

But I want to retrieve all the tags and elements of a div in "div1". So elements that will be retrieved will be

          <table>
           <tr><td>Name</td></tr>
           <tr><td>Password</td></tr>
          </table>

Not only the data.

1
  • '$(#div1)' for the entire dom object. Or '$(#div1).html()' for innerHTML Commented Jul 24, 2013 at 13:12

2 Answers 2

2

if you use this in your code you will be able to get the table which your saying

document.getElementById('div1').innerHTML;
Sign up to request clarification or add additional context in comments.

Comments

1

First and foremost, congratulation on getting started on JS. It's a beautiful scripting language. Next, I would advise you, to make your life simpler while you should play around with a pure Javascript syntax, it will make your life a whole lot easier if you get started on a library, like jQuery or Mootools. JQuery is my preference, mootools is more of a framework.

document.getElementById('div1').innerHTML;

in jquery is as elemental as $(#div1) or $(#div1).html(). Have fun learning!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.