treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Using jQuery to controll css position

  • Well, I'm half way home. Essentially, the code scrolls through a list. It works correctly for the "#last_button" but won't work for the "#first_button" and I'm not sure why. The only thing I can think of is that (".comment:last") is not returning the correct value. Thanks.

    <script type="text/javascript">
    $(document).ready(function(){

    $("#next_button").click(function(){
    var b = parseInt($(".comment:last").css("top"));
    if (b ==0) {
    $(".comment:last").css("top","0");
    } else {
    $(".comment").animate({top:"-=210px"},"fast");
    }
    });

    $("#last_button").click(function(){
    var a = parseInt($(".comment:first").css("top"));
    if (a ==0) {
    $(".comment:first").css("top","0");
    } else {
    $(".comment").animate({top:"+=210px"},"fast");
    }

    });

    });

    </script>