仅选择父元素中具有特定样式的元素

时间:2018-06-12 09:24:21

标签: jquery

我有一个jquery函数,它选择具有img-w属性的所有元素,但我希望它只选择特定img-w类中具有ul属性的元素而不选择其他类,以便img-w上发生的事情不会影响其他父元素中的其他img-w

<button class="rreorder-all btn btn-outline-primary dropdown-toggle" style="margin-left: 10px" id="saveReorder">
                            Reorder photos
                        </button><br/>
<div id="reorderHelper" style="display:none;"><span class="selected-txt mt-5 ml-5" style="text-align: left">1. Drag photos to reorder. &nbsp; 2. Click 'Save Reordering' when finished.
                            </span>
</div><br/> @if(isset($images))
<ul class="reorder row" style="    margin-left: 30px">
    @foreach ($images as $image)
    <li class="img-box" data-src="{{$image->filename}}" id="{{$image->id}}">
        <div class="img-w" style="background-image: url('{{$image->filename}}')">
            {{-- <a href=""> <img class="mb-2 uploaded-photos " src="{{$image->filename}}" alt=""></a>!--}}
        </div>
        <span style="color: #333333;position: relative;width: 100%;text-align: justify;
             display: inline;">{{$image->description}} <i class="fa fa-upload" style="margin-left: 10px; color:#333333;"></i></span>
    </li>
    @endforeach
</ul>


@endif $(document).ready(function() {
            $('.rreorder-all').on('click', function() {
                        $("ul.reorder").sortable({
                            tolerance: "pointer",
                            helper: "clone"
                        });
                        $('.rreorder-all').html('save reordering');
                        $('.rreorder-all').attr("id", "saveReorder");
                        $('#reorderHelper').slideDown('slow');
                        $('.img-w').attr("data-src", "");
                        $('.img-w').css("cursor", "move");
                        $("#saveReorder").click(function(e) {
                                    if (!$("#saveReorder i").length) {
                                        $(this).html('').prepend('saving...');
                                        $("ul.reorder").sortable('destroy');
                                        $('.img-w').css("cursor", "pointer");
                                        $('.img-w').attr("data-src", "{{$image->filename}}");
                                        $("#reorderHelper").html("Reordering Photos - This could take a moment. Please don't navigate away from this page.");
                                        var h = [];
                                        $("ul.reorder li").each(function() {
                                            h.push($(this).attr('id'))
                                        });
                                        $("#reorderHelper").hide(); // alert(h);

1 个答案:

答案 0 :(得分:1)

你可以尝试使用像这样的find()

 $(".reorder").find('.img-w').css("cursor", "move");

所以这只会选择 ul 中的.img-w,请添加自己的选择器而不是UL。根据你的代码

如果有帮助请告诉我

相关问题