Use jQuery .
jQuery is a very powerful JavaScript library that allows you to do almost anything with very little code. One of the main advantages (with the exception of its beautiful syntax) is that it is specially designed as independent of the platform and browser, so you no longer have to worry about it.
Doing what you are doing now, but in jQuery, might look something like this:
function swapText(id) { $('#id' + id) .css('font-weight','bold').css('color','red').css('font-size','150%') .html(myarray[id][0]); } function originalText(id) { $('#id' + id).css('color','black').html(myarray[id][1]); }
Of course, if you define a CSS class for your โmodifiedโ style, you can simply use $('#id'+id).addClass('swapped'); and $('#id'+id).removeClass('swapped'); .
In addition, there are really good ways to hook events, so you donโt even need to define functions with names if you don't want to:
$('div').hover(function() { $(this) .css('font-weight','bold').css('color','red').css('font-size','150%') .html(myarray[id][0]); }, function() { $('#id' + id).css('color','black').html(myarray[id][1]); });
source share