12

I'm trying to expand the height of a div element with the following code:

html:

<div id="expandbtn">more..</div>

<div id="portfolio"><div class="itemweb" title="lol" rel="#derp"><div class="thumb"><img src="images/items/skills.jpg" title="Skills" rel="#derp"/></div>

script:

$('#expandbtn').click(function(){
$('#portfolio').animate({height:'72px'}, 500);});

css:

#portfolio {
width:914px;
height:295px;
margin:0 0 0 -8px;
overflow:hidden;}

But it won't work. What am i doing wrong?

4
  • from original height (295px) to 72px it means you're contracting it :) .. btw, your code seems fine.. maybe u can't see anything because there is no background on portfolio div
    – stecb
    Commented Dec 5, 2011 at 17:17
  • works for me, check this: jsfiddle.net/TrDtc/4 Commented Dec 5, 2011 at 17:17
  • I just pasted the script below the content just before </body> tag and that worked!
    – Biels
    Commented Dec 5, 2011 at 17:21
  • It works fine for me apart from a rather embarrassing moment where I hadn't set jsfiddle to jQuery. Deleted my 'answer' as it wasn't really one.
    – SpaceBeers
    Commented Dec 5, 2011 at 17:23

3 Answers 3

33

your code is just fine. you can also try

$('#portfolio').css("height","74px");

try putting some backgroung color or image to visualize clearly

fiddle : http://jsfiddle.net/49HQM/4/

5

Try toload it when the document is ready:

  $(document).ready(function(){
      $('#expandbtn').click(function(){
      $('#portfolio').animate({height:'72px'}, 500);
   });
1
  • Nice touch with the animation Commented May 1, 2020 at 18:41
0

It works just fine, but try setting position and a background color to see the element, like THIS FIDDLE.

Also, it will not animate the height of the elements inside the portfolio div, if that is what you are trying to do (unless size of those elements are in percent)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.