Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
XML
thanks for your time and first of all I'm a noobie who's been learning by his own javascript so I don't manage quite good the selectors to achieve what I want. Here it's my problem:

html

<ul id='stuff' class='goods'>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li><span class='highlighted'>list item 4</span></li>
<li>list item 5</li>
</ul>

<ul id='stuff2' class='goods'>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li>item 4</li>
<li>list item 5</li>
</ul>

CSS

.highlighted{
    color: red;
}

.goods{
    border:1px solid red;
    cursor: pointer;
    padding: 0px;
    list-style: none;
}

.match_group{
    border: 1px solid black;
}

Look here pelase: * http://jsfiddle.net/nero_noob_123/ctcn7kfy/2/

basically what I want to achieve with the jquery and javascript it's the following.... but I don't know how write it as a condition so try to read it as follows:

$('#stuff2').addClass('match_group');

$('#stuff2').addClass('match_group');

if($('li').has('span.highlighted').length){ //so span exist!
        $('span.highlighted').closest('.goods').addClass('match_group');
    }else if($('.goods').hasClass('match_group') && // span.highlight DOESN'T EXIST inside .goods) {
/// remove the match_group class from '.goods' where span.highlight doesn't exist
    }else{ if any of the '.goods' classes has span.highlighted inside them, don not apply .match_group

    }


PD: feel free to modify the crapy code I wrote to acheive what I need, thank you!
Posted
Updated 8-Mar-15 8:40am
v2
Comments
You did not mention what you are trying to achieve.

1 solution

Look like you are trying to set the border of the ul to black when there is some highighted li in it, you are almost there, just this:
if($('li').has('span.highlighted').length > 0)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900