Juanjo Moreno
Juanjo Moreno

Reputation: 1

addEventListener onmouseout changing function parameters not working

Hello everyone I have declared a function in javascript...

    function CellOut(e, b, c){
       document.getElementById(e).style.backgroundColor = b;    
       document.getElementById(e).style.color= c; 
    }

And a div element...

    <div id="celdiahora" onmouseout="CellOut('celdiahora', '#f88', '#fff')">Some text</div>

Later i need to change only the parameters of the function CellOut into the onmouseout event calling the next function...

    function ChangeBackgroundAndColor(e, newb, newc){
       document.getElementById(e).addEventListener("mouseout", function(){
          CellOut(e, newb, newc)}, false);
    }

Example, if I call ChangeBackgroundAndColor('celdiahora', '#8f8','#fff') it must change the second parameter when the onmouseout event call the function CellOut. But this code do not change the color parameters when onmouseout event of the div occurs.

Some idea ?

Thanks.

Upvotes: 0

Views: 91

Answers (1)

Juanjo Moreno
Juanjo Moreno

Reputation: 1

I have find one solution that i think is not the best, but it works:

I have create diferent functions with the diferents parameters:

function CellOutRed(e){
   document.getElementById(e).style.backgroundColor = red;    
}
function CellOutBlue(e){
   document.getElementById(e).style.backgroundColor = blue;    
}

And i change the onmouseout event...

function ChangeBackgroundRed(e){
   document.getElementById(e).addEventListener("mouseout", function(){
      CellOutRed(e)}, false);
}
function ChangeBackgroundBlue(e){
   document.getElementById(e).addEventListener("mouseout", function(){
      CellOutBlue(e)}, false);
}

It works...

Upvotes: 0

Related Questions