Search code examples
jquerycode-readability

jQuery code, how I can do easier to read


I wanna try to make my code easier to read and I'm looking for a solution something like this, in Visual Basic:

 With $('.class or sector') {
    $(this).removeClass('some-class');
    $(this).addClass('some-other-class');
 } End With

I tried this, but it doesn't work:

$('.class or sector') = function() {
    $('.class or sector inside > *', this).addClass('some-class');
}

.container is a class inside .footer-finale maybe anyone can help me


Solution

  • jQuery uses a fluent interface, so you can chain your calls.

    $('.class')
        .removeClass('some-class')
        .addClass('some-other-class');
    

    You can also assign a variable:

    var item = $('.class');
    item.removeClass('some-class');
    item.addClass('some-other-class');