Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/310431-andself-not-working/
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
Link to comment
https://forums.phpfreaks.com/topic/310431-andself-not-working/#findComment-1576106
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.