I think you need to save the changed background color of each button id. below code should help you. check console.log
var data = {}; function changeColor(e){ data[e] = "blue"; $('#' + e).css('background-color', data[e]); } changeColor('btn1'); console.log(data); changeColor('btn2'); console.log(data); changeColor('btn3'); console.log(data);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <button id="btn1">Button1</button> <button id="btn2">Button2</button> <button id="btn3">Button3</button>
In your code, it seems like you passed id as an object, not a string. data.e , where e is a data property, the parameter value is not passed.
source share