官术网_书友最值得收藏!

  • JavaScript:Moving to ES2015
  • Ved Antani Simon Timms Narayan Prusty
  • 122字
  • 2021-07-09 19:07:42

Chaining

Chaining jQuery methods allows you to call a series of methods on a selection without temporarily storing the intermediate values. This is possible because every setter method that we call returns the selection on which it was called. This is a very powerful feature and you will see it being used by many professional libraries. Consider the following example:

$( '#button_submit' )
  .click(function() {
    $( this ).addClass( 'submit_clicked' );
  })
  .find( '#notification' )
    .attr( 'title', 'Message Sent' );x

In this snippet, we are chaining click(), find(), and attr() methods on a selector. Here, the click() method is executed, and once the execution finishes, the find() method locates the element with the notification ID and changes its title attribute to a string.

主站蜘蛛池模板: 徐闻县| 明光市| 曲周县| 旬邑县| 大化| 理塘县| 中山市| 古田县| 开化县| 泗水县| 始兴县| 伊吾县| 南陵县| 邻水| 鲁甸县| 洱源县| 柞水县| 富宁县| 鄂伦春自治旗| 钦州市| 德令哈市| 营山县| 赤城县| 明溪县| 兴和县| 甘德县| 马山县| 寻乌县| 祥云县| 广丰县| 永昌县| 石城县| 桦甸市| 同仁县| 广饶县| 京山县| 西乌| 手游| 绥中县| 呼和浩特市| 兴仁县|