Skip to main content

Posts

Showing posts with the label width

jQuery - Get Width of Element when Not Visible (Display: None)

It seems like in jQuery when an element is not visible width() returns 0. Makes sense, but I need to get the width of a table in order to set the width of the parent before I show the parent. As noted below, there is text in the parent, that makes the parent skew and look nasty. I want the parent to be only as wide as the table and have the text wrap. <div id="parent"> Text here ... Can get very long and skew the parent <table> ... </table> Text here too ... which is why I want to shrink the parent based on the table </div> CSS: #parent { display: none; } Javascript: var tableWidth = $('#parent').children('table').outerWidth(); if (tableWidth > $('#parent').width()) { $('#parent').width() = tableWidth; } tableWidth always returns 0 since it is not visible (is my guess since it gives me a number when visible). Is there a way to get the width of the table without making the parent visible?

getting the image width from the href tag instead from img tag

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 $(