Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何获取parentNode_Jquery_Jquery Ui - Fatal编程技术网

Jquery 如何获取parentNode

Jquery 如何获取parentNode,jquery,jquery-ui,Jquery,Jquery Ui,嘿,伙计,这只是个简单的问题 我正在制作一个可排序的拖放系统,我需要它,当用户将消息拖到删除框时,它将.remove()将消失(我们将其删除),但问题是它删除了消息中的一些小元素,如主题,我希望它删除整个div,例如“message”元素之一。那么,如何获取该节点的parentNode,即消息div 它会刷新消息,因此不必担心消息 我的密码是 <div class="message 1" id="1"> // I want to remove this part and only

嘿,伙计,这只是个简单的问题

我正在制作一个可排序的拖放系统,我需要它,当用户将消息拖到删除框时,它将.remove()将消失(我们将其删除),但问题是它删除了消息中的一些小元素,如主题,我希望它删除整个div,例如“message”元素之一。那么,如何获取该节点的parentNode,即消息div

它会刷新消息,因此不必担心消息

我的密码是

<div class="message 1" id="1">  // I want to remove this part and only this part
                    <ul id="8">
                        <li class="dragable" id="2">
                            <!-- Dragable -->

                        </li>
                        <li class="checkbox" id="4">
                            <input type="checkbox" name="checkbox" class="checkbox" id="messagecheck1">
                        </li>
                        <li id="3"> 
                            <p> hi</p>
                        </li>
                    </ul>
                </div>
它们是具有相同类名的多个元素,因此我不能在一行代码中删除消息类,我必须单独选择元素并像那样删除它


链接

如果您使用的是jQuery,应该会出现一个快速的google搜索
.parent()

附加的


如果您需要使用选择器来查找不是直接父项的祖先,您也可以使用
.closest(selector)

关于这一点有什么不清楚的地方…这就是我在开始时所做的,就像我说的,它删除了父项,但我需要删除父项…然后使用
.parent()
获取该元素的parent@Ryanc1256-使用
.closest(“div.message”)
。哇,谢谢你真的不知道。最近的事。工作得很愉快
$(".messageholder").sortable({          
        start: function(event, ui){
            $(ui.item).css("opacity", "0.25");
            draggable_sibling = $(ui.item).prev();
            $(".deletebox").show();
        },

        stop: function(event, ui) {
            $(".deletebox").hide();
            if (dropped) {
                if (draggable_sibling.length == 0)
                    $('.messageholder').prepend(ui.item);

                draggable_sibling.after(ui.item);
                dropped = false;
            }
            $(ui.item).css("opacity", "1.00");
        },
        update: function(event, ui){
            //Use's Xhr to save the position of the message
            var array = [];
            $(".messageholder div").each(function(e){
                 array.push($(this).attr('id'));
            });
            $.ajax({
                type: 'POST',
                url: 'json/save.php',
                data: ("data="+array)                           
            });

        }   


    }); 

        $(".refresh").click(function(){
            checkmessages();        
        });     

        $(".deletebox").droppable({         
                drop:function(event, ui){
                    dropped = true;                 
                    $(event.target.parentNode).closest('div').remove();


                    }               

        });     


        $(".messageholder").disableSelection();