本文介绍了我怎样才能设定这个条件? (Jquery的/ JavaScript的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:随时修改我写的crapy代码以实现我的需要,谢谢!



PD: feel free to modify the crapy code I wrote to acheive what I need, thank you!

推荐答案




这篇关于我怎样才能设定这个条件? (Jquery的/ JavaScript的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 12:22