使用jQuery删除第一个li元素中的第一个img [英] Remove first img in first li element with jquery

查看:177
本文介绍了使用jQuery删除第一个li元素中的第一个img的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的html

<ul class="products">
    <li>
        <a href="#" class="product-images">
            <span class="featured-image">
                <img src="img1.jpg"/>
                <img src="img1-1.jpg"/>

            </span>
        </a>
    </li>
    <li>
        <a href="#" class="product-images">
             <span class="featured-image">
                <img src="img2.jpg"/>
                <img src="img2-2.jpg"/>
             </span>
        </a>            
    </li>

//some other li elements
</ul>

我想做的是在 first li 元素中获取 fist 图像,并使用jQuery删除它.

What I want to do is get the fist image in the first li element and remove that with jQuery.

我尝试过的

jQuery (document).ready(function(){
        jQuery('.products li:first .featured-image img:first').remove();
});

但这会删除第一个跨度下的所有img.

But that removes all img under first span.

需要任何帮助.

推荐答案

您可以选择第一个li,然后在其中找到第一个img并将其删除 演示 .

You can select first li and then find first img inside it and remove it DEMO.

$('.products li').first().find('img').first().remove()

另一种方法是

$('.products li:first img:first').remove()

这篇关于使用jQuery删除第一个li元素中的第一个img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆