简体   繁体   English

使用CSS将所有元素选择到div中

[英]Select all elements into a div with css

I'm trying to select all elements into a div, so when I put the mouse outside do something. 我试图将所有元素都选择到div中,所以当我将鼠标放在外面时,请执行一些操作。 Selecting directly the div's id is not working properly. 直接选择div的ID不能正常工作。 There are some way to select an element and all their child? 有一些方法可以选择一个元素及其所有子元素?

$("...").mouseout(function(){

});

I have a div and other div into it that appear on mouse over, but when I try to hide it after appear with mouse out of it and leave the father div, the div is still there. 我有一个div和其他div出现在鼠标悬停时,但是当我尝试用鼠标将其显示出来后将其隐藏并离开父div时,该div仍然存在。

I tryed something like: 我尝试了类似的东西:

$(".release").mouseover(function(e){
    var selected_row = $(this).attr('id');
    var request_id = $(this).attr('id').slice(8);

    var position_top = $('#'+selected_row).offset().top;
    var position_left = $('#'+selected_row).offset().left;

    jQuery("#request_notes").css( "display", "inline" );
    jQuery("#request_notes").css( "position", "absolute" );
    jQuery("#request_notes").css( "top", position_top );
    jQuery("#request_notes").css( "left", mouse_left );

});

$("#request_notes").mouseout(function(){
    jQuery("#request_notes").css( "display", "none" );
});

When I do mouse out of the father div, the one that appear is still there. 当我从父div中移出鼠标时,出现的那个仍然存在。 So I would like to do mouse out, of the father and his child. 因此,我想从父亲和他的孩子那里抽出来鼠标。

http://jsfiddle.net/sebasparola/vRqH4/6/ http://jsfiddle.net/sebasparola/vRqH4/6/

try 尝试

$("#request_notes").mouseout(function(){
    $(this).hide();
});

When you select an element, you already have its children. 选择元素时,您已经有了它的子元素。 You can use built in jquery functions like find() to perform actions on the element's children. 您可以使用内置的jquery函数(例如find()对元素的子元素执行操作。

If you're looking for a specific way to build a generic selector, you can pass jquery a comma separated list of elements you're looking for, just like in CSS. 如果您正在寻找一种构建通用选择器的特定方法,则可以像使用CSS一样,将要查找的元素的列表以逗号分隔的形式传递给jquery。 ie $("div, p, span, h1, h2") $("div, p, span, h1, h2")

代替使用mouseout使用mouseleave

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM