I'm curious as to how other people indent/break long jQuery chains, as I can never decide what is more readable (particularly when using .end() to "close" a block of methods e.g.

                                 left: 12
                                 opacity: 0.5
                            .end().children().load("/homepage.html", function() {

How would YOU format this?

*edit included a method with a callback to make it a bit more interesting

  • 1
    NOTE: This is not a question that should have been asked on Stack Overflow as there's not actually a problem with the code. It's a question of style. It might be OK for Code Review, but it is on topic here.
    – ChrisF
    Apr 14, 2011 at 16:36
  • Not sure that editing your question after people have answered it is a very nice thing to do. Your example now just seems contrived. In any event, past a certain point you have to start refactoring behavior out to simplify things. Apr 14, 2011 at 17:25
  • Also, if you find an answer useful, you might consider accepting it. Apr 14, 2011 at 17:28

2 Answers 2


I use indent to signify hierarchy.


For indentation I'd say that selector would be equivalent of opening a block ({), while .end() -- equivalent of }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.