Trying to use text from a link in a selector
I'm (obviously) new to jQuery and can't figure out why this isn't working. I want to select the matching Article based on the links in the Aside:
- <html>
<head>
<title>Link Copy</title>
<script type="text/javascript" src="../jquery-1.9.1.js"></script>
<script type="text/javascript">
$("document").ready(function() {
// Trying to get copy link from aside to articles
$("aside section hgroup a").each(function() {
// Find matching Article heading
// This works:
//$("article h1:contains('Article 1')").append("xxx"); // Works!?
// This doesn't work:
//var sText = $(this).text();
//$("article h1:contains(sText)").append("xxx");
//This works:
//$(this).append($(this).text());
});
});
</script>
</head>
<body>
<header id="header">
<hgroup>
<h1>Main Title</h1>
<h2>Main Subtitle</h2>
</hgroup>
</header>
<article>
<h1>Article 1</h1>
</article>
<aside class="aside">
<header>
<h1> Health & Nutrition </h1>
<p> Are you where you want to be? </p>
</header>
<p> It's all about making the choices that will give us the results we desire. </p>
<section>
<hgroup>
<h1><a href="../article1.php">Article 1</a></h1>
</hgroup>
<p>
This includes not only food, but what we breath and put on our bodies
as well. It even involves what we think!
</p>
</section>
<section>
<hgroup>
<h1><a href="../article2.php">Article 2</a></h1>
</hgroup>
<p>
When we are not able get everything our body needs, high-quality
supplements can fill the gap.
</p>
</section>
<section>
<hgroup>
<h1><a href="../article3.php">Article 3</a></h1>
</hgroup>
<p>
Exercise is necessary for our bodies to be in shape.
</p>
</section>
</aside>
<article>
<h1>Article 2</h1>
</article>
<article>
<h1>Article 3</h1>
</article>
</body>
</html>
Thank you!
Brent