What does `a > b` mean?

2019-03-01 05:36发布

I'm reading a tutorial about creating a shoutbox with jquery, php and ajax. In the jquery code, it creates a variable like this

var messageList = $(".content > ul");

There is a "content" class in the html, and it has an unordered list in it. But I don't understand the syntax .content > ul in the creation of the variable.

Can you explain?

HTML

 <div class="content">  
            <h1>Latest Messages</h1>  
            <div id="loading"><img src="css/images/loading.gif" alt="Loading..." /></div>  
            <ul>  
            <ul>  
        </div>  

4条回答
Melony?
2楼-- · 2019-03-01 06:04
爱情/是我丢掉的垃圾
3楼-- · 2019-03-01 06:13

It searches for a ul that's the direct child of .content, so if you'd change the html to

<div class="content">
   <div>
      <ul></ul>
   </div>
</div>

your selector wouldn't return anything. There's more info on all kinds of selectors on http://api.jquery.com/category/selectors/

查看更多
相关推荐>>
4楼-- · 2019-03-01 06:16
我命由我不由天
5楼-- · 2019-03-01 06:19

It indicates the shoutbox should be applied to a "ul" thats the immediate child of ".content". Without the ">" symbol, it applies to any ul thats a child of .content

查看更多
登录 后发表回答