SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Simple jquery not working?

    It's been a little while since I did any jquery and for some reason I am stuck on my second line of code.

    var $pheight = $(window).height();

    $('#col_left').css('height', $pheight);

    All I need to do is take the height of the window and resize #col_left to that value.
    Simple right? I can't seem to see anything wrong with it. I do have jquery installed on the site so that is not the problem. I also have tested the variable with an alert and am getting the correct value. What is wrong here?

    Thanks all

  2. #2
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the #col_left element display: block? If it's currently display: inline then it won't do anything with the height.

    Quick check would be to set block on it:
    Code:
    var $pheight = $(window).height();
    jQuery('#col_left').css({
       height: $pheight,
       display: "block"
    });
    Could be something else in your css conflicting as well, I'd check there first before you change any javascript.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. Good thinking too but still not working.

    Here is my css:

    #col_left{
    position:relative;
    width:203px;
    height:1000px;
    background-image:url(../images/col_fill.png);
    background-repeat:repeat-y;
    background-color:#f1f1f1;
    float:left;
    }

    Any other thoughts?

  4. #4
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about giving it a unit of measurement:

    Code:
    jQuery('#col_left').css({
       height: $pheight + "px",
       display: "block"
    });

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea I thought about that but still nothing. When I check the markup in firebug it isn't attaching the style attribute at all...? I have this working on other sites that is why I am totally confused as to why this isn't working. Any other ideas...?

    Really appreciate the help

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Document.ready
    Just a few weeks and already forgot....
    idiot!!!!!!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •