Jump to content

andSelf() not working

Recommended Posts


I am trying to get refreshed on jQuery so I bought O'Reillys jQuery cookbook. I'm having trouble with the exercise on using andSelf() to manipulate the parent of the selected element; though my code is exactly like the books.

<!doctype html>
	<meta charset="utf-8">
	<title>Untitled Document</title>

		$('div').find('p').andSelf().css('border', '1px solid #993300');

From my understanding my jQuery should add a border to the <div> but it doesn't. When I remove andSelf() it does add a border to the 2 <p> tags though. Am I doing something wrong?

Share this post

Link to post
Share on other sites

Okay...turns out that function is depreciated. Using addBack() fixed the problem.

Can I mark this as the answer to my question? Or should I just delete the post?

Share this post

Link to post
Share on other sites

andSelf was deprecated back in 1.8. That was a number of years ago. Your book may be slightly out of date.

As for this thread, leave it. It's fine. Maybe someone else will find it on Google and your follow-up will answer their problem.

  • Great Answer 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.