What does `a > b` mean?

孤街浪徒 提交于 2020-01-21 20:07:30

问题


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>  

回答1:


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/




回答2:


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




回答3:


It's a child selector.




回答4:


css child selector



来源:https://stackoverflow.com/questions/6640751/what-does-a-b-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!