I am quite a noob for javascript so sorry for this very basic question: So i've been looking around but found no answer for this very simple question (I strongly believe its not that hard but couldn't figured out why my code doesn't work). So i try to make an Image appear after I click on another image. This is similar to what happened when you click on a picture and then the picture enlarged while making the background darker. My method is having an img inside a div container in which the div container will be on top of the page. The div container will have display:none attribute and i will use javascript to get the div ID and set the display:none to display:block. However I stumbled upon something I don't know that make my code not work. Hope anyone can help me find the problem that I wasn't aware of.
This is my Code:
HTML
enter <!DOCTYPE html>
<head>
<?php
header('Content-Type:text/html;Charset=UTF-8');
?>
<title> Western Drive - Driving Changes </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="stylesheet.css" type=text/css>
<link rel="stylesheet" href="testing.css" type=text/css>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10/jquery.min.js">
</head>
<body>
<script>
window.onload=function(){
function preview(arg1)
{
document.getElementById("img1").style.display='block';
document.getElementById("img1").src = arg1+'_Drawing.jpg';
}
}
</script>
<div id ="preview_image" style="display:none;">
<img id ="img1" src="Pictures/Product/SingleSpeedReducer/WPA_Drawing.jpg">
</div>
<div id="container">
<?php include("header.php");?>
<?php include("menu.php");?>
<h2 id=Sub_title> Single Speed Reducer </h2>
<!----------------------------------put the content----------------------------- here-->
<div id=box style="border-top:solid 1px black ; border-bottom:solid 1px black">
<div id=pic_model><img src="Pictures/Product/SingleSpeedReducer/SingleReducer.jpg"></img></div><!-- div for pic_model-->
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPA.jpg"></img> </div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDA.jpg" onclick="preview('Pictures/Product/SingleSpeedReducer/WPDA')"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDKA.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDKS.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPO.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDO.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPX.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDX.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPKA.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDKA.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPKS.jpg"></img></div>
<div id=pic_selector><img src="Pictures/Product/SingleSpeedReducer/WPDKS.jpg"></img></div>
</div><!-- div untuk box-->
<!----------------------------------end the content----------------------------- here-->
<?php include("selector.php");?>
<div class="push"></div>
</div><!--div for container-->
<?php include("footer.php");?>
</body>
CSS
#preview_image{ position:absolute;
width:53%;
height:70%;
margin:12% 10% 10% 25%;
border:solid 3px red;
z-index:1;}
#preview_image img{
max-height:100%;
max-width:100%;
margin:0% 0% 0% 0%;
}
#preview_image onclick{
max-height:100%;
max-width:100%;
margin:0% 0% 0% 0%;
}
When i try to click img WPDA it supposed to make the change the display:none into display:block , but nothing happened...
#img1element? I don't find it anywhere in your code, and (2) IDs have to be unique, but you have multiple instances of#pic-selector