JQuery animate div's width onclick

css, html, jquery, jquery-animate, width

Solution

Its because you have missed `#` in your selector.

Just try to use the `this` reference inside that click event to achieve what you want,

$("#foldit").click(function () {
    $(this).animate({"width": "165px"}, "fast");
});

As per your new requirement you can try like this,

$('#foldit').click( function() {
    var toggleWidth = $(this).width() == 165 ? "100px" : "165px";
    $(this).animate({ width: toggleWidth });
});

DEMO

Problem

I have no idea why this doesn't work. JQuery: ``` $("#foldit").click(function () { $("foldit").animate({"width": "165px"}, "fast"); }); ```

Original source