¿Es posible cambiar una función invocada por un evento existente onmouseover o onmouseout? Para el siguiente ejemplo, ¿hay alguna manera para que ChangeItemAEvent cambie la función onmouseover "ItemA" de ChangeColor() a ChangeColorBack()? Actualmente necesito declarar una función completamente nueva() que siento que no es elegante porque estoy repitiendo el código cuando debería poder llamar a una función existente.Cambia dinámicamente onmouseover o onmouseout para llamar a una función diferente
javascript:
function ChangeColor(elementid)
{
document.getElementById(elementid).style.background = "Orange";
document.getElementById(elementid).style.color = "Black";
}
function ChangeColorBack(elementid)
{
document.getElementById(elementid).style.background = "Black";
document.getElementById(elementid).style.color = "White";
}
function ChangeItemAEvent()
{
document.getElementById("ItemA").onmouseover = function() {
document.getElementById("ItemA").style.background = "Black";
document.getElementById("ItemA").style.color = "White";
};
}
html:
<span id="ItemA" onmouseover="ChangeColor(this.id)">
<button id="ButtonB" onclick="ChangeItemAEvent()">