Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  141] [ 3]  / answers: 1 / hits: 48687  / 12 Years ago, mon, october 22, 2012, 12:00:00

I am trying to change john to mike. I have no idea why its not working.



<span id=user>John</span>


I am trying this but not working i have no clue why not working.



function set() {
document['getElementById']('user')['value'] = Owner;
// owner value is mike
}

More From » innerhtml

 Answers
4

If you want to change the id, use



 document['getElementById']('user').id = 'mike'; 


or, more classically,



 document.getElementById('user').id = 'mike'; 


If you want to replace John (that is not the ID but the content of the span), do



 document.getElementById('user').innerHTML = 'mike'; 

[#82428] Saturday, October 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lara

Total Points: 462
Total Questions: 100
Total Answers: 102

Location: Jersey
Member since Mon, Jun 14, 2021
3 Years ago
lara questions
;