Reputation: 11
I asked another question (Javascript - Link Name Changing with restrictions) similar to this yesterday, but after trying to apply the same fix, nothing seemed to happen. Hopefully I can get some insight.
I applied the first solution:
var elements = document.getElementsByClassName("time")[0].getElementsByTagName("a");
for(var i = 0, j = elements.length; i<j; i++){
elements[i].innerHTML = "Time Review";
}
which worked great. However, on another piece of code, there is:
<div class='validatable' id='style_picker'>
<div class='selector'>
<span class='selection'></span>
<span class='handle'></span>
</div>
<ul type='none'>
<li class='time'>
<span class='style_item'></span>
<span class='copy'>time</span>
</li>
</ul>
</div>
I'm trying to get the time to show up as 'time review'. Once again, I only have the header/footers to work with for javascript, and I can't change any of the actual code myself. I'm a little confused as to why the aforementioned code doesn't change the text. Could anyone shed some light on this and/or provide a solution?
Thanks!
Upvotes: 0
Views: 72
Reputation: 35720
var elements = document.getElementsByClassName("time")[0].getElementsByTagName("a");
Notice getElementsByTagName("a")
, this will get tags: <a>
, in the new version of your code, it's <span>
, so replace "a" to "span".
If you just want to replace time to time review, just use:
document.getElementsByClassName("copy")[0].innerHTML = "time review";
Upvotes: 1
Reputation: 7512
It didnt work because the text you're trying to change is in a <span>
tag now
var elements = document.getElementsByClassName("time")[0].getElementsByTagName("span");
for(var i = 0, j = elements.length; i<j; i++){
elements[i].innerHTML = "Time Review";
}
Upvotes: 3