开发者

UL inside UL JQuery Problem

I've got the following UL's setup:

<ul class="parent">
   <li>
      <ul class="child">
         <li>
            test
         </li>
     </ul> 
  </li>
</ul>

I'm trying to .ap开发者_开发技巧pend() to only "parent" with the following code:

$('ul.parent li:first-child').before(msg);
$('ul.parent:empty').append(msg);

It works, however, it's adding msg to both the "parent" UL and the "child" UL. I know it's because I'm using first-child (or highly suspect anyways). How can I access JUST the "parent" UL? I've looked around and just can't seem to find the answer.

Any help would be greatly appreciated

Thanks


Add the child combinator > for matching only the immediate li:

$('ul.parent > li:first-child').before(msg);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜