Click here to Skip to main content
15,884,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m trying to create an image gallery in asp.net using jquery here is the code
JavaScript
<script type="text/javascript">
        $(document).ready(function () {
            $(".thumbnail").click(function () {
                var address = $(".Bigimage").attr("src");
                $("#popup").fadeIn("slow")
                $("#lightbox").attr("src", address);
                
            });
            $("#popup").click(function () {
                $("#popup").fadeOut("fast");
            });
        });
    </script>

and this is asp.net code
C#
<div style="background:#e7e5e5; height: 674px;" >
        <img src="cars thumbnails/Chevrolet thumbnail/03_chevrolet_sail_u_va_caviar_black.png" class="thumbnail"   title="Mercedes-Benz SLK55 AMG" />
    <img src="cars%20thumbnails/Chevrolet%20thumbnail/2014-Chevrolet-Impala-LTZ-side.png" class="thumbnail"   /> 
    <img src="cars%20thumbnails/Chevrolet%20thumbnail/2014-chevrolet-impala-navy-rear-left-angle.png" class="thumbnail"   />
   </div>
    </div>
    <div id="popup">
        <div id="center" style="border:hidden;">
            <img  src="car images/chevrolet/03_chevrolet_sail_u_va_caviar_black.jpg" class="Bigimage" style="height:550px; width:600px;"/>
            <img src="car images/chevrolet/2014-Chevrolet-Impala-LTZ-side.jpg"  class="Bigimage" style="height:550px; width:600px;" />
        <img id="lightbox" src="upcomming_Cars/Mercedes-Benz SLK55 AMG.PNG" />
       
                    </div></div>

this is my asp.net image now the problem i m facing is my first thumbnail and its related big image is getting open properly but when i click on the next image the same image opens when i click on the 1st image plz do help me as soon as you can
Posted

1 solution

Hi Siddesh,
The problem is with the way you are reading the image in below line:
var address = $(".Bigimage").attr("src");

With the above code, you are reading all the Bigimage class elements and then reading the attribute value. Hence it might be returning you the first occurrence only and that may be the reason you are getting first image always.


Try reading the image from $(this).attr("src");

Let me know if this resolves your problem.
 
Share this answer
 
Comments
siddesh_bobade 6-Dec-13 11:23am    
No it didnt
Member 10434230 9-Dec-13 4:33am    
Please put some additional details with your comments...
What are you getting in $(this) -> it should be the image element on which you are performing click...

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