1
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 in the second click, after that it works correctly in the first click. Why it happens?
tried <a href="#" onclick="zoom('example','examplo2','examplo3');">Calls function</a>?
– Rod
Yes, but I get the same result.
– Matheus