开发者

jQuery - "this" element and "parent(s)"

I am solving following problem - I have on my page statement of items from DB table and every this item is printed to div. If the user move cursor of mouse on this div, so then will be show div with other information.

            <div class="dost">
                3 days | 
                <span>deliv</span>
                <div class="deliv_bubble">
                  <div><strong>aaa</strong></div>
                                      <div><strong>bbb</strong></div>
                                      <div><strong>ccc</strong></div>
                </div>
            </div>

$('div.dost span').mouseover(function() {
    $('div.dost div.deliv_bubble').show(); 
});

On the page is e.g. 100 times printed this html structure. My problem is, that when I move the mouse cursor on the text deliv, so the div deliv_bubble will be showed, but unfortunately 100 times... I am trying to display this just one time...

Can开发者_高级运维 anyone help me, please, what I am doing wrong? Thank you


Do this:

$('div.dost span').mouseover(function() {
    $(this).parent().find('div.deliv_bubble').show(); 
});

$(this).parent() will return the corresponding parent div.dost

Hope this helps. Cheers


Try this:

$('div.dost span').mouseover(function() { 
    $(this).siblings('div.deliv_bubble').show(); 
});


$('div.dost span').mouseover(function() {
    $(this).siblings('.deliv_bubble').show(); 
});

should do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜