2013-09-12 2 views
2

Это не работает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--> 
+0

кажется хорошо для меня http://jsfiddle.net/arunpjohny/kXLEn/1/ –

+0

«Выбирает все элементы, которые являются п-й ребенок своих родителей.» С http://api.jquery.com/nth-child-selector/. – Stefan

+0

Какие элементы вы ожидаете получить фон? –

ответ

1

Вы можете попробовать это.

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

Вы можете использовать формулу, чтобы получить дочерний элемент

$('.text_read).eq(0); 
2

использовать вместо :nth в .eq()

DEMO

$('.text_read:nth(2)'); 
Смежные вопросы