开发者

mouseover parent = find() child id name

when mouseover #divlayer, find() id of child span

HTML:

<div id="divlayer">
        <p>title&l开发者_StackOverflow社区t;/p>            

        <span id="apple">apple</span>
        <span id="orange">orange</span>
        <span id="kiwi">kiwi</span>
</div>

jQuery:

$('span').hide();
$('#divlayer').mouseover(function(){
    $('span').show();
    $(this).find(???).attr('id');
});

edit: my bad, I should have clarified my question. the spanchildren are hidden, when the mouse pointer goes over <p>title</p>, id of each span child is returned.

Basically, <p>title</p> is visible at first, and when the mouse goes over the it, children are shown and ids are returned individually.


Maybe like this.. (Edited to meet your last requirements)

$('#divlayer').mouseover(function(){
    $('span', $(this)).each(function(){
        alert($(this).attr('id'));
    });
});


Based on your update

$('#divlayer').mouseover(function(){
    $('span').show();
});

$('#divlayer > p').mouseover(function() {
    $('#divlayer').find('span').each(function() {
       alert($(this).attr('id'));
    });
});


HTML:

<div id="divlayer">
    <span class="mouseoverClass" id="apple">apple</span>
    <span class="mouseoverClass" id="orange">orange</span>
    <span class="mouseoverClass" id="kiwi">kiwi</span>
</div>

jQuery:

$(document).ready(function(){
    $('#divlayer').mouseover(function(){
        var accumulator = new Array();
        $(this).find('span').each(function(a,dom){accumulator.push(dom.id);});
        alert(accumulator[0]);
    })
});

here you have it. it takes all id's and pushes it onto accumulator. then you can do whatever you need with these id's

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜