.andSelf()
Syntax
.andSelf()
Parameters
None
Return value
The new jQuery object.
Description
Add the previous set of elements on the stack to the current set.
Add the previous selection to the current selection
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div.selected").next().andSelf().css("background", "yellow");
});
</script>
</head>
<body>
<body>
<div>asdf</div>
<div>asdf</div>
<div>asdf</div>
<div class="selected">asdf</div>
<div>asdf</div>
</body>
</html>
The following code uses .andSelf() to add a div back onto the stack after doing a .find() manipulates the stack.
<!DOCTYPE html>
<html>
<head>
<script src='http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js'>
</script>
<script >
$(function(){
document.writeln( $("div") );
document.writeln( $( "div" ).find("p") );
document.writeln( $( "div" ).find("p").andSelf() );
});
</script>
</head>
<body>
<div>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
</div>
</body>
</html>
Home
JavaScript Book
jQuery
JavaScript Book
jQuery
DOM:
- jQuery DOM
- $("html tags"):generate code with the jQuery wrapper function.
- .add()
- .addClass()
- .after()
- .andSelf()
- .append()
- .appendTo()
- .attr()
- .before()
- .children()
- .clone()
- .closest()
- .contents()
- .css()
- .detach()
- .filter()
- .first()
- .get()
- .has()
- .hasClass()
- .height()
- .html()
- .index()
- .innerHeight()
- .innerWidth()
- .insertAfter()
- .insertBefore()
- .is()
- .last()
- .map()
- .next()
- .nextAll()
- .nextUntil()
- .not()
- .offset()
- .offsetParent()
- .outerHeight()
- .outerWidth()
- .parent()
- .parents()
- .parentsUntil()
- .position()
- .prepend()
- .prependTo()
- .prev()
- .prevAll()
- .prevUntil()
- .remove()
- .removeClass()
- .removeAttr()
- .replaceAll()
- .replaceWith()
- .siblings()
- .scrollLeft()
- .scrollTop()
- .slice()
- .text()
- .toArray()
- .toggleClass()
- .unwrap()
- .val()
- .wrap()
- .wrapAll()
- .wrapInner()
- .width()