Skip to content

Bug 4446 - Add selector support to .andSelf()#203

Closed
gabrielgrant wants to merge 3 commits intojquery:masterfrom
gabrielgrant:bug_4446
Closed

Bug 4446 - Add selector support to .andSelf()#203
gabrielgrant wants to merge 3 commits intojquery:masterfrom
gabrielgrant:bug_4446

Conversation

@gabrielgrant
Copy link

http://bugs.jquery.com/ticket/4446

Filters prevObject with the given selector (if provided) before adding to the result.

Example (for the docs):

<!DOCTYPE html>
<html>
<head>
  <style>

  body { font-size:16px; font-weight:bolder; }
  p { margin:5px 0; }
  </style>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
  <div>
    <span>Hello</span>
    <p class="selected">Hello Again</p>
    <div class="selected">And Again</div>

    <p>And One Last Time</p>
  </div>
<script>$(".selected").parent().andSelf("p").css("color", "blue");</script>

</body>
</html>

@timmywil
Copy link
Member

Instead of checking typeof, do !!selector to catch null and invalid selectors. Filter will do this, but going to filter would be unnecessary and slower in that case.

@gabrielgrant
Copy link
Author

woops, nope. that doesn't work (should have finished running the tests before pushing...)

@timmywil
Copy link
Member

Of course, sorry about that. I just see !!selector so often. =)

@gabrielgrant
Copy link
Author

No problem: like i said, if i'd been a good boy and finished running the tests before pushing... :)

@gnarf
Copy link
Member

gnarf commented Mar 14, 2011

I like this idea and its implementation, can't tell you how many times I've done $something.find( selector ).andSelf().filter( selector )

@rentalhost
Copy link

It's a good idea, really.

@dmethvin
Copy link
Member

dmethvin commented Sep 2, 2011

Ticket was closed wontfix in the 1.7 feature vote. Sorry!

@dmethvin dmethvin closed this Sep 2, 2011
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants