Forecast toggle span using find()


#1

Has anyone else done this span toggle class between glyphicon-plus glyphicon-minus . I found it tricky and instructions very confusing. I have finally manged to come up with working solutions but not sure if it's the right way but it does the job. Let me know what you think of it. Here's the mine:

var main = function() {
    $('.day').click(function() {
        $(this).next().toggle('.hourly');
        console.log(this);
        var $el = $(this).find('span.glyphicon');
        $($el).toggleClass('glyphicon-plus glyphicon-minus');
    });
};

$(document).ready(main);

#2

You can definitely accomplish the same thing with fewer lines of code :wink:

var main = function() {
  $('div.day').click(function() {
    $(this).next().toggle();
    $(this).find("span").toggleClass("glyphicon-minus");
  });
};