Item 1 Ti...">

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 tried using:

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

but no luck. Even tried to use:

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

but still no luck.

I just want to change the text and leave it all the same.

Am I doing something wrong?

+7
source share
2 answers

try it

 window.onload = function(){ document.getElementById("item1").innerHTML = "Item was changed"; } 
+12
source

you can make a function and all of it after loading the page

 var changeText = function(text){ document.getElementById("item1").innerHTML = text; } window.onload = function() { changeText(' some text '); } 
0
source

All Articles