Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .width() and css('width') returning invalid values

I'm trying to get the width of a parent from an element. To do this I'm using:

parent = $("#"+id).parent().attr("id");
parentWidth = $('#'+parent).width();

I've also tried:

parentWidth = $('#'+parent).css('width');

At first I used

$('#'+id).parent().width(); 

this didnt work either.

The parent variable is correctly set, however, the width of a parents div is 90%, .width() returns 90, and .css('width') returns 90px. In my .css widht is set to 90%, i also tried adding it in the style tag in the element itself.

<div id="tabs" style="height:90%;width:90%;">

in the CSS file:

#tabs{
height:90%;
width:90%;
position:absolute;
z-index:10;
overflow:hidden;
}

I keep getting 90 as return value. What am I doing wrong? Thanks

This is the page I'm talking about: http://www.amsterdamslyceum.lelie.demodomein.com/index.php Don't mind the db errors, didnt set up the db on the host yet as I just started developing.

like image 820
jewetnit Avatar asked Nov 29 '25 23:11

jewetnit


1 Answers

$('#'.id).parent().width(); must be $('#' + id).parent().width();

do you check the parent? first in the browse console (FF and Chrome) check if this code returns the parent that you want $('#' + id).parent();

like image 140
MCSI Avatar answered Dec 01 '25 13:12

MCSI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!