0

i am using following way to open the image in light box but it opens the image which is selected i want that when i click any image it should open another images how to do this

<script type="text/javascript" >
    $(document).ready(function(){
        $(".linkbutton").click(function(){
            var address= $(this).attr("src");
            $("#popup").fadeIn("slow");
            $("#lightbox").attr("src",address);
        });
        $("#close").click(function(){
            $("#popup").fadeOut("fast");
        });
    });
</script>

Following in body

<div>
    <img src="image/smallicon_2.png" class="linkbutton">
</div> 

<div id="popup">
    <div id="center">
        <img id="lightbox" src="image/popup_page_1.png" >
        <img id="close" src="images/close.png" alt="close" >
    </div>  <!-- #center --> 
</div>

2 Answers 2

1

Add an attribute in the image element to reference the new image:

<img src="image/smallicon_2.png" class="linkbutton" data-light="image/bigimage_2.png" />

Then replace:

var address= $(this).attr("src");

with:

var address= $(this).attr("data-light");
Sign up to request clarification or add additional context in comments.

Comments

0

Change the line that determines the src of the image

var address= $(this).attr("src");

So it uses the src of the image you want.

1 Comment

i am using this code for 3 image like i have two button and for each i want different so how will i aasing in this it will get only for one image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.