Reputation: 625
How do I select the nodes that have <a name="something"></a>, so that I can bold its contained text?
<p>
<a name="test"></a>
Test 1
</p>
<p>
<a href="test2"></a>
Test 2
</p>
<div>
<a name="test3"></a>
Test 3
</div>
Desired output:
Test 1
Test 2
Test 3
Upvotes: 2
Views: 371
Reputation: 145378
You can use .has()
method:
$("p,div").has("a[name]").css("font-weight", "bold");
or :has()
selector:
$("p:has(a[name]),div:has(a[name])").css("font-weight", "bold");
DEMO: http://jsfiddle.net/bWvwa/
Upvotes: 6