0

I'm trying to use jQuery to expand and contract the height of a div when a link is clicked, and I can't for the life of me work out what I'm doing wrong.

Here's the html;

<div id="slider" class="map">
    <div id="map-canvas">this is a test</div>
</div>

<div id="slider-map"><a href="#" id="expand">Expand +</a></div>

The slider height is 300px by default in the CSS

Here's the jQuery;

$(document).ready(function() {

    var maxWidth = 500;
    var minWidth = 300;

    $("#expand").click(
        function(){
            var curHeight = $("#slider").height();
            if(curHeight==300)
            {
                $("#slider").animate({height: maxWidth+"px"}, { queue:false, duration:400 });
                $("#expand").html("Contract <small style='font-size:12px;'>-</small>");
            }
            else
            {
                $("#slider").animate({height: minWidth+"px"}, { queue:false, duration:400 });
                $("#expand").html("Expand <small style='font-size:12px;'>+</small>");
            }
        return false;
    });
}

I've tried this without calling the Google maps API in the map-canvas div too see if that was the culprit, but it still won't work.

Any help would be much appreciated

bananabread_
  • 27
  • 1
  • 4

1 Answers1

0

You forgot to close the $(document).ready(); function

js:

$(document).ready(function(){

    var maxWidth = 500;
    var minWidth = 300;

    $("#expand").click(

        function(){
            var curHeight = $("#slider").height();
            alert(curHeight);
            if(curHeight==300)
            {
                $("#slider").animate({height: maxWidth}, { queue:false, duration:400 });
                $("#expand").html("Contract <small style='font-size:12px;'>-</small>");
            }
            else
            {
                $("#slider").animate({height: minWidth}, { queue:false, duration:400 });
                $("#expand").html("Expand <small style='font-size:12px;'>+</small>");
            }
        return false;
    });
});

css:

.map
{
    background-color:green;
}

<div id="slider" class="map">
    <div id="map-canvas">this is a test</div>
</div>

html:

<div id="slider-map"><a href="#" id="expand">Expand +</a></div>

works for me. tested in chrome ;)

user1534664
  • 3,258
  • 8
  • 40
  • 66