mongoose00318 Posted March 31, 2020 Share Posted March 31, 2020 Hi, 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> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <div> <p>Paragraph</p> <p>Paragraph</p> </div> <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"> </script> <script> $('div').find('p').andSelf().css('border', '1px solid #993300'); </script> </body> </html> 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? Quote Link to comment https://forums.phpfreaks.com/topic/310431-andself-not-working/ Share on other sites More sharing options...
mongoose00318 Posted March 31, 2020 Author Share Posted March 31, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/310431-andself-not-working/#findComment-1576091 Share on other sites More sharing options...
requinix Posted March 31, 2020 Share Posted March 31, 2020 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/310431-andself-not-working/#findComment-1576106 Share on other sites More sharing options...
mongoose00318 Posted March 31, 2020 Author Share Posted March 31, 2020 Haha yea...I thought it was super up-to-date. I was disappointed to find out it's from '09...thanks Quote Link to comment https://forums.phpfreaks.com/topic/310431-andself-not-working/#findComment-1576108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.