I would like to replace abcName with xyzName?
<tr>
<td>
<b class="abcName">Bob</b>
</td>
</tr>
Using this, but on page load nothing changes:
var bobo = document.getElementsByTagName("td");
function user(a, b, c) {
try {
if (bobo[c].innerHTML.match('>' + a)) {
bobo[c].className = b;
}
} catch (e) {}
}
function customs() {
for (i = 0; i < bobo.length; i++) {
classChange("Bob", "xyzName", i);
}
}
setInterval("customs()", 1000);
Although I’m not real sure if what you’re doing with the interval and whatnot is the best approach, you can:
http://jsfiddle.net/zBmjb/
Note, you also had the wrong function name in your
forloop as well.If you use jQuery, this would be MUCH simpler.
EDIT
Using jQuery:
http://jsfiddle.net/zBmjb/1/
Also, note the use of the anonymous function instead of using a string in
setInterval(). This allows you to not useeval(), which is considered expensive and potentially harmful.EDIT 2
If you wanted to pass in a list of name and class associations, you could use an array with objects, like so:
http://jsfiddle.net/zBmjb/4/
It feels messy though, since it searches for all selected nodes, then for each found, loops over the current node for each name looking for a matched value, all while doing this once a second. The cleaner approach would be to see if the name value from the current node was found:
http://jsfiddle.net/zBmjb/5/
EDIT 3
If you need multiple values, you can make the value for the object an object as well.