Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to change li tag text

I am using the following HTML:

<li id="item1" data="icon: 'base.gif', url: 'page.htm', target: 'Page'">Item 1 Title</li>

I am trying to change the Item 1 Title part to something else.

I have tried using:

document.getElementById("item1").innerHTML = "Item was changed";

but had no luck. Even tried using:

document.getElementById("item1").value = "Item was changed";

but still no luck.

I am only wanting to change the text and leave eveything else the same.

Am I doing something wrong?

like image 807
Aaron Avatar asked Sep 12 '12 04:09

Aaron


1 Answers

try this

window.onload = function(){
 document.getElementById("item1").innerHTML = "Item was changed";
}
like image 81
Nudier Mena Avatar answered Oct 22 '22 19:10

Nudier Mena