Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello
i put an image as an answer but it will be hidden till user click a button to see it
notice: the code will be Repeated in the same page with another pics for another answer
what is the nice code for that ?

What I have tried:

i tried with a code but when i repaste it with another pic makes pointing for the same pic
the code is
HTML
<pre><a id="show_image">Show Image</a>
<img id="my_images2" style="display:none" 

src="https://i49.servimg.com/u/f49/19/59/89/07/02010.jpg">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $('#show_image').on("click", function(){
         $('#my_images').show('slow');
      });
   });
</script>
Posted
Updated 4-Jul-18 21:53pm

1 solution

I have taken some time develop this for you
HTML
<html>
	<body>
		<img height="200px" width="200px" src="sc.png" id='image_1' style="display:none" />
		<a class='testClass' data-id=image_1>Show Image</a><br>
		<img src="sc.png" id='image_2' style="display:none" />
		<a class='testClass' data-id=image_2>Show Image</a>
		
		
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
		<script>
			$(document).ready(function(){
					$('.testClass').on("click", function(){
					console.log(document.getElementById(this.getAttribute("data-id")));
					
					$("#"+this.getAttribute("data-id")).show();
					
					});
			});
		</script>
	</body>
</html>

sc.png is test file that i used.
 
Share this answer
 
Comments
Member 13898220 5-Jul-18 3:11am    
thank you for your efforts
this code gives a list of pics, i need every pic with it's code which i can control it's id number and change it
my page is an exam,question and answer,some questions need pics as an answer
thank you again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900