harish
harish

Reputation: 2493

Accessing HTML table values in javascript

I am using HTML5 with phonegap. I have a table defined as follows.

<table id = "myTable">
   <tr><td>Name</td><td class="center">:</td><td><div id="name"></div> </td></tr>
   <tr><td>Age</td><td class="center">:</td><td><div id="age"></div> </td></tr>
   <tr><td>Country</td><td class="center">:</td><td><div id="country"></div> </td></tr>
</table>    

I want to set values to "name", "age", and "country" from javascript. I tried it as follows.

document.getElementById('name') = 'John'

But this doesn't give me the required output. How can that be done? Thank you.

Upvotes: 0

Views: 111

Answers (4)

Dr. Dan
Dr. Dan

Reputation: 2288

You can set innerHTML to set html inside an element.

document.getElementById('name').innerHTML= 'John'

Upvotes: 1

Ahsan Khurshid
Ahsan Khurshid

Reputation: 9469

Use document.getElementById('name').innerHTML = 'John';

SEE DEMO

Upvotes: 3

Eric Lin
Eric Lin

Reputation: 11

document.getElementById('name').innerText = 'John'

Upvotes: 1

Dr. Dan
Dr. Dan

Reputation: 2288

document.getElementById('name').innerHTML= 'John'

Upvotes: 3

Related Questions