1. $(document).ready(function(){  
  2.       
  3.     jQuery.fn.showTags = function (n) {  
  4.       var tags = this.map(function () {   
  5.                               return this.tagName;   
  6.                             })  
  7.                         .get().join(", ");  
  8.       $("b:eq(" + n + ")").text(tags);  
  9.       return this;  
  10.     };  
  11.   
  12.     $("p").showTags(0)  
  13.           .find("span")  
  14.           .showTags(1)  
  15.           .css("background", "yellow")  
  16.           .end()  
  17.           .showTags(2)  
  18.           .css("font-style", "italic");  
  19.   
  20.   });  
  1. <p>  
  2.     Hi there <span>how</span> are you <span>doing</span>?  
  3.   </p>  
  4.   <p>  
  5.     This <span>span</span> is one of   
  6.     several <span>spans</span> in this  
  7.     <span>sentence</span>.  
  8.   </p>  
  9.   <div>  
  10.     Tags in jQuery object initially: <b></b>  
  11.   </div>  
  12.   <div>  
  13.     Tags in jQuery object after find: <b></b>  
  14.   </div>  
  15.   <div>  
  16.     Tags in jQuery object after end: <b></b>  
  17.   </div>  

 

end()
将返回到执行find("span")操作之前的匹配元素集合状态

 

$("div").find("p").andSelf().addClass("border");
将匹配div元素集合增加到匹配p元素集合中。

 posted on 2010-11-19 11:02  H&M  阅读(182)  评论(0编辑  收藏  举报