How to get the html text of CLASS and use another function to change the html text?
For example, there are lot of tags (td) using the same class. But the inner html of that class will be changed after the function called.
HTML
<table>
<tr><td class="number">1</td></tr>
<tr><td class="number">2</td></tr>
<tr><td class="number">3</td></tr>
<tr><td class="number">4</td></tr>
<tr><td class="number">5</td></tr>
</table>
jQuery / JS
function ChangeNumber(){
var cusid_ele = document.getElementsByClassName('number');
for (var i = 0; i < cusid_ele.length; ++i) {
var item = cusid_ele[i];
item.innerHTML = number(item.innerHTML);
}
}
function number(n){
if(n == 1)
return "one";
else if(n == 2)
return "two";
else if(n == 3)
return "three";
else if(n == 4)
return "four";
else if(n == 5)
return "five";
}
window.onload = function(){ ChangeNumber() };
I don't know if my codes are incorrect. Yes, it is not working, so I need help. I just refer to this URL: https://stackoverflow.com/a/15560734/2903208
Could anyone try this? And if success, well that's great!
I want the output that will be:
one
two
three
four
five
Is it possible?
Thanks in advance! ^_^