Skip to content
jQuery

Method Chaining

Chain jQuery methods and use end() to restore context.

#chaining#fluent-api

Code

jquery
// Most methods return the jQuery object, enabling chains
$("#box")
  .addClass("highlight")
  .css({ color: "red", "font-weight": "bold" })
  .slideDown(300)
  .find("span")
    .text("Updated")
    .end()
  .attr("data-status", "ready");

// end() pops the most recent filtering/traversal step
$("ul")
  .find("li")
    .addClass("item")
    .end()
  .addClass("list");