开发者

UL inside UL JQuery Problem

开发者 https://www.devze.com 2023-03-12 00:45 出处:网络
I\'ve got the following UL\'s setup: <ul class=\"parent\"> <li> <ul class=\"child\"> <li>

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

精彩评论

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