I'm using this simple function to conditionally change CSS in Javascript:
function zoom(obj, icon, menu) {
var el = document.getElementById(obj);
var img = document.getElementById(icon);
var men = document.getElementById(menu);
var men2 = document.getElementById(menu + "2");
if (el.style.width === "360px") {
el.style.width = "500px";
el.style.height = "308px";
men.style.width = "500px";
men2.style.width = "500px";
if (el.style.width === "500px") {
img.src = "img/icons/png/minimize1.png";
}
} else {
el.style.width = "360px";
el.style.height = "222px";
men.style.width = "360px";
men2.style.width = "360px";
if (el.style.width === "360px") {
img.src = "img/icons/png/expand.png";
}
}
}
It is used to change the size of 3 elements with different Id's.
But when I use the function in a link:
<a href="javascript:zoom('exemplo','exemplo2','exemplo3');">Chama função</a>
The function is only applied on the second click, after that it works correctly on the first click. Why does this happen?