JQuery USES the andSelf of to contain the previous selection set

  • 2020-03-30 03:02:22
  • OfStack

A new result set is generated when we select and filter the wrapper set using Destructive Method. Such as:

HTML

$lt; Div $gt;
$lt; P $gt; Com.lowagie.text.paragraph $lt; / p $gt;
$lt; P $gt; Com.lowagie.text.paragraph $lt; / p $gt;
$lt; / div $gt;

For the DOM Tree above, of course

$(' div '). The find (" p ")

To get the p elements that all div elements contain, but the selection result definitely does not contain the div element itself.
If you call andSelf() chaining after find, you can include previous selection($('div')) in the result set as well.

Usage, for example,

For the above HTML code, use

$(' div '). The find (" p "). The CSS (' border ', '1 px solid # 993300');

CSS effects can only be applied to p elements
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201405191745214.gif? 2014419174535 ">  
But by adding andSelf() after find(), CSS also works with all div elements
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201405191746015.gif? 2014419174617 ">

Related articles: