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 7445777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:06:53+00:00 2026-05-29T12:06:53+00:00

i am working on a project in which i require the width of a

  • 0

i am working on a project in which i require the width of a image from href when i click on the specific image the width if the image displays in a alert .

the following is the href and image code i am using

    <li>
      <a href="<?php echo $pic;?>?id=<?php echo $id;?>&pic=<?php echo $picID;?>" data-title="" data-desc=" " data-rel="group2" data-bw="<?php echo $pic;?>"  class="lightbox" id="plzx" >
      <img src="<?php echo $pic;?>"  width="160" height="160" title="Click To View"/></a>                       
    </li>

whenever i try to get the width of the image it takes the image width from the img tag not from the href . as the img tag width is already defined “160” . is there a way possible for getting the width of the image from the <a href

i am using the following code which is nit working

   $('a').click(function() {
       var image = $("<img />").attr("src", $(".lightbox").attr("href"));
       $(document).append(image);
       alert(image.height());
       alert(image.width());
       image.remove();
    });

the html code

       <li>
                    <a href="uploads/kareena-kapoor-144a_$1$Ni5.St4.$kPORmHFjcfGBJjn2KHSis0.jpg?id=3&pic=101" data-title="" data-desc=" " data-rel="group2" data-bw="uploads/kareena-kapoor-144a_$1$Ni5.St4.$kPORmHFjcfGBJjn2KHSis0.jpg"  class="lightbox" id="plzx" >

                    <img src="uploads/kareena-kapoor-144a_$1$Ni5.St4.$kPORmHFjcfGBJjn2KHSis0.jpg"  width="160" height="160" title="Click To View"/></a>

    </li>           
  • 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-29T12:06:54+00:00Added an answer on May 29, 2026 at 12:06 pm

    Based on something like:

    <a href="/path/to/big.jpg"><img src="/path/to/small.jpg"></a>
    

    This should do it:

    $('a').click(function() {
        $(new Image()).load(function() {
            alert(this.width); // image width
            alert(this.height); // image height
        }).attr('src', this.href);
    });
    

    Update: If you need to continue your program using the width/height, try:

    var width,height;
    $('a').click(function() {
        $(new Image()).load(function() {
            width = this.width;
            height = this.height,
            onLoaded();
        }).attr('src', this.href);
    });
    function onLoaded() {
        alert(width);
        alert(height);
        // continue...
    }
    

    You don’t need to append the temporary image to the document, but you do need to add a load listener before you extract width/height.

    Remember that the AdBlock extension can affect the outcome of the extraction in webkit, so please turn it off when debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a project which requires migration of content from different
I am working on a new project which requires a image gallery as well
I am currently working an a webapp, using mongoengine and django, which will require
I have just joined a project which require working on ARM based micro-controllers.. i
I'm working on something which will require monitoring of many forms. From outside the
I have started working on a project which requires Natural Language Processing. We have
I'm working on a project for my companies intranet which requires that multiple attached
Iam working on a project which involves writing a Mork File (Mork is a
I'm working on a project which is just about to start, and since I
I'm working in a project which needs to clean up some third party XSD

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.