Jquery 限制ID内的操作?

Jquery 限制ID内的操作?,jquery,Jquery,如何使脚本仅适用于特定ID?我有多个类名为的div。不同ID中的item post。如何将脚本限制为仅在特定id内工作 <script type="text/javascript"> $( ".next" ).click(function() { $(".item-post:first").insertAfter($(".item-post:last")); $(".item-post:first").css('display','none')

如何使脚本仅适用于特定ID?我有多个类名为的div。不同ID中的item post。如何将脚本限制为仅在特定id内工作

<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>

编辑:更新为显示问题的fiddle:

我尝试了此操作,但脚本将在其他ID中显示“insertBefore/insertAfter”元素,因为还有其他父元素的子元素为.item post。此方法使脚本无法正常工作。您是否尝试过
$(“#layout-education-1.item post:last”)
是的,我也尝试过。这阻止了脚本做任何事情。我没有看到小提琴,但可能是因为我在iPhone上抱歉,忘了添加链接。
$('#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()
    });
});
$(".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()
});