javascript - jquery :nth-child() class is not working

标签 javascript jquery

这不起作用

$(".text_read:nth-child(2)").css("background", "transparent url('images/text_read2.png') no-repeat");

以上代码的结果与以下代码相同

$(".text_read").css("background", "transparent url('images/text_read2.png') no-repeat");

我的 HTML 代码是

<div class="welcome">
                    <p class="welcometext">MORE UPCOMING NEWS FOR INTERNATIONAL EVENTS</p>
                    <div class="all_international_img row-fluid">
                    <div class="welcome-image span4 international_img">
                        <img src="images/img1.png">
                        <div class="text_read">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a </div>
                    </div><!--all_international_img row-fluid-->
                    <div class="welcome-image span4 international_img">
                        <img src="images/img1.png">
                        <div class="text_read">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a </div>
                    </div><!--all_international_img row-fluid-->
                    <div class="welcome-image span4 international_img">
                        <img src="images/img1.png">
                        <div class="text_read">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a </div>
                    </div><!--all_international_img row-fluid-->
                    </div><!--all_international_img-->
                </div><!--welcome-->

最佳答案

看起来您想使用 .eq()相反

$('.text_read:eq(2)')

DEMO

关于javascript - jquery :nth-child() class is not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18759298/

相关文章:

javascript - 旋转图像跟随鼠标 jquery 平滑过渡

javascript - javascript函数参数中的命名冗余

javascript - Angular 中 tsconfig.json 文件的 lib 数组中的 dom 是什么?

javascript - jQueryeach() 只选择最后一个值

javascript - 使用 moment 检查时间是否重叠?

javascript - 如何使用 regex-Javascript 检查字符串中是否存在 "undefined"测试

javascript - Jquery一次清除多个文本字段的值

php - jQuery 不会发布文本区域?

javascript - 来自动态创建的元素的操作不起作用

javascript - 重新启动 Gif 动画