jQuery Selector对应的图像和li

时间:2016-01-30 10:39:58

标签: javascript jquery html css jquery-selectors

我想在点击相应的图片后更改li标签的列表样式。这就是我到目前为止所做的。

jsFiddle

$('#foodOrder').click(function() {
      $(this " > li").css('list-style', 'disc');
    });
#foodOrder {
  list-style: circle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<span id="foodOrder"><img id="orderFood" src="http://zoarchurch.co.uk/content/pages/uploaded_images/91.png" alt="" /><li>CIABATTA</li></span>
      <span id="foodOrder"><img id="orderFood" src="http://zoarchurch.co.uk/content/pages/uploaded_images/91.png" alt="" /><li>BAKERS BUN</li></span>

1 个答案:

答案 0 :(得分:1)

修复了jQuery选择器(语法错误)和HTML:

  1. <li>必须仅位于<ul><ol><menu>
  2. <span>必须仅包含Phrasing content<ul>Flow content。您应该使用<div>然后。
  3. JSFiddle

    $('.foodOrder').click(function() {
        $('li', this).css('list-style', 'disc');
    });
    .foodOrder li {
        list-style: circle;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
    <div class="foodOrder">
        <img class="orderFood" src="http://zoarchurch.co.uk/content/pages/uploaded_images/91.png" alt=""/>
        <ul>
            <li>CIABATTA</li>
        </ul>
    </div>
    <div class="foodOrder">
        <img class="orderFood" src="http://zoarchurch.co.uk/content/pages/uploaded_images/91.png" alt=""/>
        <ul>
            <li>BAKERS BUN</li>
        </ul>
    </div>