2015-02-21 2 views
-1

Как заставить скрипт работать только для определенного ID? У меня есть несколько div с именами классов .item-post в разных идентификаторах. Как ограничить скрипт работой только внутри определенного идентификатора?Ограничить действие внутри идентификатора?

<script type="text/javascript"> 
    $(".next").click(function() { 
     $(".item-post:first").insertAfter($(".item-post:last")); 
     $(".item-post:first").css('display','none'); 
     $(".item-post:first").fadeIn() 
    }); 
    $(".prev").click(function() { 
     $(".item-post:last").insertBefore($(".item-post:first")); 
     $(".item-post:first").css('display','none'); 
     $(".item-post:first").fadeIn() 
    }); 
</script> 

Это то, что я пробовал:

$('#layout-education-1').is({ 
    $(".next").click(function() { 
     $(".item-post:first").insertAfter($(".item-post:last")); 
     $(".item-post:first").css('display','none'); 
     $(".item-post:first").fadeIn() 
    }); 
    $(".prev").click(function() { 
     $(".item-post:last").insertBefore($(".item-post:first")); 
     $(".item-post:first").css('display','none'); 
     $(".item-post:first").fadeIn() 
    }); 
}); 

EDIT: обновление с скрипку показывая вопрос: http://jsfiddle.net/m5s8ad68/1/

ответ

1
$(".next").click(function() { 
    $("#layout-education-1 .item-post:first").insertAfter($("#layout-education-1 .item-post:last")); 
    $("#layout-education-1 .item-post:first").css('display', 'none'); 
    $("#layout-education-1 .item-post:first").fadeIn() 
}); 
$(".prev").click(function() { 
    $("#layout-education-1 .item-post:last").insertBefore($("#layout-education-1 .item-post:first")); 
    $("#layout-education-1 .item-post:first").css('display', 'none'); 
    $("#layout-education-1 .item-post:first").fadeIn() 
}); 
+0

Я попытался это, но сценарий будет потом "InsertBefore/InsertAfter" элементы в других идентификаторах, потому что есть другие родители с дочерними элементами с .item-post. Этот метод нарушает работу скрипта. – Xarcell

+0

Вы пробовали '$ (" # layout-education-1 .item-post: last ")' –

+0

Да, я тоже уже пробовал это. Это останавливает выполнение скрипта. – Xarcell

Смежные вопросы