Indentation / chained jquery for readability

I'm curious how other people backtrack / break long jQuery chains, since I can't decide which is more readable (especially when using .end () to “close” a block of methods, for example.

$(this).not(":has(.pointer)").append(pointerHtml) .end() .closest("li").toggleClass("selected") .siblings().removeClass("selected") .andSelf().removeClass("pre-selected") .end().end() .filter(".selected").prev().addClass("pre-selected"); 

How do you format this?

+4
source share
1 answer
 $(this).not(":has(.pointer)") .append(pointerHtml) .end() .closest("li") .toggleClass("selected") .siblings() .removeClass("selected") .andSelf() .removeClass("pre-selected") .end() .end() .filter(".selected") .prev() .addClass("pre-selected"); 
-1
source

Source: https://habr.com/ru/post/1348129/


All Articles