0

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.

4 Answers 4

3

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

SEE DEMO

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

a div does not have value attribute
@Dr. Dan: You've edited your answer and replaced value with innerHTML
1
document.getElementById('name').innerText = 'John'

Comments

1

You can set innerHTML to set html inside an element.

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

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.