Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding specific elements with jQuery

I have the following markup.

<h6>Brand</h6>

<ul>
    <li>Orange</li>
    <li>Black</li>
    <li>Green</li>
</ul>

<h6>Colour</h6>

<ul>
    <li>Green</li>
    <li>Blue</li>
    <li>Black</li>
    <li>Orange</li>
</ul>

I am unable to change or physically add into this markup, so hence trying to manipulate with jQuery.

What I want to achieve from this is to be able to change the word Black to Purple. But only the word Black that appears after the H6 containing "Colour"

I have this so far:

$("h6:contains('Colour'):.jqueryCheck:contains('Black')").html("Purple");

This however does not work... Why not?

like image 910
Rory Standley Avatar asked Mar 28 '12 15:03

Rory Standley


1 Answers

$("h6:contains('Colour')").next('ul').children("li:contains('Black')").html("Purple");

Or all as one selector string:

$("h6:contains('Colour') + ul li:contains('Black')").html("Purple");
like image 178
Rocket Hazmat Avatar answered Oct 16 '22 21:10

Rocket Hazmat