Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:06:20+00:00 2026-05-27T02:06:20+00:00

I am working on jquery ui dialog box to display multiple images. Here is

  • 0

I am working on jquery ui dialog box to display multiple images. Here is my working code for a single image:

http://jsfiddle.net/pZMvf/

As you can see in above code I have one image with class userImage and it has a rel attribute which i am storing original width and height of image width|height and through css I have set this image size to 200px width and height 120px, So when user click on the image he get full size image.

Now my problem is i wants to add multiple images this way on page with diffrent sizes, so for example here is my next HTML and i include one more image in page:

<div class="userImg">
  <img class="userImage" src="http://i.imgur.com/ad3ct.png" alt="" rel="610|374" />
    <div class="dialog"></div>
</div>

<div class="userImg"><img class="userImage" src="http://i.imgur.com/83Fko.png" alt="" rel="510|274" /><div class="dialog"></div></div>

Example with multiple images: http://jsfiddle.net/pZMvf/1/

Now i have 2 images on page, my problem is here i am not sure how can i give image size from rel attribute of clicked image as I have it included before click function and it is displaying twice each image.

var getSizeFromRel = $(".userImage").attr('rel');
var size = getSizeFromRel.split('|');
var imgWidth = size[0];
var imgHeight = size[1];

Thank you for any help.
Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:06:20+00:00Added an answer on May 27, 2026 at 2:06 am

    Set the width/height attributes on the img tag in your .click() event:

    var img = $(this).attr("src");
    var sizes = $(this).attr('rel').split('|');
    
    $(dialog).prepend(
        $('<img />').attr({
            src: img,
            width: sizes[0],
            height: sizes[1]
        })
    );
    
    $(dialog).dialog('option', { 'width': sizes[0], 'height': sizes[1]});
    $(dialog).dialog('open');
    

    Edit for comments with autoOpen:

    Setting the autoOpen option to true in your dialog will not work as expected because your dialog is empty when you create it, you populate the content on the click of an image.

    What you can do is get the querystring variable value for ‘display’ and if it is true, trigger a click on the first image to sort-of ‘auto-open’ the dialog:

    First here’s a function to extract querystring values (found here):

    // extract a querystring value
    // key: the name of the qstring parameter
    // default_: a default value (optional)
    function getQuerystring(key, default_)
    {
        if (default_==null) default_=""; 
        key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
        var qs = regex.exec(window.location.href);
        if(qs == null)
            return default_;
        else
        return qs[1];
    }
    

    Set autoOpen: false for the dialog.

    Then, at the end of the document.ready handler:

    // get value of 'display' qstring param, default value is false (do not auto-open)
    if (getQuerystring('display', false)) {
        $(".userImage:eq(0)").trigger('click');
    }
    

    Somes notes on your code:

    You don’t have to make an instance of the dialog for each image like you do, it opens two dialogs:

    <div class="userImg">
        <img class="userImage" src="http://i.imgur.com/ad3ct.png" alt="" rel="610|374" />
        <div class="dialog"></div>
    </div>
    

    Only make one <div /> for the dialog outside your userImg, you’ll get one dialog and you change the content anyway:

    <div class="dialog"></div>
    
    <div class="userImg">
        <img class="userImage" src="http://i.imgur.com/ad3ct.png" alt="" rel="610|374" />
    </div>
    
    <div class="userImg">
        <img class="userImage" src="http://i.imgur.com/83Fko.png" alt="" rel="200|50" />
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery UI Dialog working great on my ASP.NET page: jQuery(function() {
I am using the jquery dialog widget to display a modal box. However when
Asp.net ajax autocomplete inside jquery ui dialog not working, Please help The autocomplete list
I have blinking text modal dialog box and slideshow with jquery. They working just
I am using jQuery dialog in asp.net. It is working fine for me. The
I am using the jQuery Dialog in ASP.NET. I have it working fine with
I am working with jQuery Form and ASP.NET MVC. Preview 5 of ASP.NET MVC
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
I am trying to use Jquery Dialog box in place of Java script standard
I'm trying to insert a partial into a jquery dialog box. The dialog box

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.