0

Working on this code and am quite stuck.. What I'm trying to achieve is that when there are more then 2 selections in the selection div, the overlay message's bottom position moves from 10px (defined in CSS) to 90px (defined in the jQuery)。问题是它适用于所有覆盖消息(90px),即使当我记录结果时,我得到 2,3 和 4 作为单独的结果。为什么不将结果分别应用于每个包装器 div?这不是每个函数的作用,应用于每个单独的函数吗?

谢谢!

演示:http: //jsfiddle.net/6qD52/

代码:

$(".overlay").each(function() {
    selection_number = $(this).parent().find(".selections").find(".selection").length;
    console.log(selection_number);

     if ((selection_number) > 2) {
        $(".overlay_message").css({bottom: 90});
     }
});
4

3 回答 3

3

$('.overlay_message')选择所有覆盖消息。您想要元素内部的那个:

$(this).find(".overlay_message").css({bottom: 90});
于 2013-05-01T18:18:18.403 回答
3

你想选择你正在操作的元素内的.overlay_message那个:

$(this).find('.overlay_message')
于 2013-05-01T18:18:33.417 回答
2

尝试这个:

// Selects the 'overlay_message' div inside the current 'overlay' div
$(this).find(".overlay_message").css({bottom: 90});

而不是这个:

// Selects all the 'overlay_message' div
$(".overlay_message").css({bottom: 90});
于 2013-05-01T18:19:51.230 回答