<script>
function zeigeBildGross1(Bild1){
document.getElementById("Bild1").width = 500;
document.getElementById("Bild1").height = 300;
}
function zeigeBildGross2(Bild2){
document.getElementById("Bild1").width = 500;
document.getElementById("Bild1").height = 300;
}
function zeigeBildGross3(Bild3){
document.getElementById("Bild1").width = 500;
document.getElementById("Bild1").height = 300;
}
function zeigeBildGross4(Bild4){
document.getElementById("Bild1").width = 500;
document.getElementById("Bild1").height = 300;
}
</script>
<noscript>
Bitte JavaScript in Ihrem Browser aktivieren!
</noscript>
</head>
<body>
<img id="Bild1" width=300 height=200 onclick=zeigeBildGross(Bild1) src="http://getafteritsales.com/wp-content/uploads/2015/04/Brett-Zalaski-1.png" >
<img id="Bild2" width=300 height=200 onclick=zeigeBildGross(Bild2) src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Number_2_in_light_blue_rounded_square.svg/1024px-Number_2_in_light_blue_rounded_square.svg.png"><br>
<img id="Bild3" width=300 height=200 onclick=zeigeBildGross(Bild3) src="https://p3cdn2static.sharpschool.com/common/resources/images/Cliparts/Math/Number%203%20Violet.png">
<img id="Bild4" width=300 height=200 onclick=zeigeBildGross(Bild4) src="http://www.clker.com/cliparts/m/e/u/E/z/k/yellow-rounded-number-4-md.png"><br>
</body>
Hello, I want to code a website using HTML and JS, where 4 pictures are shown. If I press on one picture, it should be resized.
Is it possible, to get a "dynamic" variable?
My idea was, to get a new variable which can have the content Bild1, Bild2, Bild3 or Bild4, depending on which picture was pressed before so there's not the same function for each case just with a different word.
For example:
function zeigeBildGross(){
var x = <!-- depending on which pic was pressed either: Bild1, Bild2, Bild3 or Bild4 !-->
document.getElementById(x).width = 500;
document.getElementById(x).height = 300;
}
Is that possible?
Thank you for reading, Stöger