Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.
I have some div element that their ids are 1,2,3,...
These div s have internal div s which their dispaly property are none and their ids are 1_d,2_d,3_d,... according to thir external div,for example internal div for div with id:1 is 1_d.
I want to show internal divs when mouseenter event is applied.
when I do like below codes,it is ok:

JavaScript
$("#" + 1).mouseenter(function () {
        $("#" + 1 + '_d').stop(true, true).show('clip');
    }).mouseleave(function () {
        $('#' + 1 + '_d').stop(true, true).hide('clip');
    });
    $("#" + 2).mouseenter(function () {
        $("#" + 2 + '_d').stop(true, true).show('clip');
    }).mouseleave(function () {
        $('#' + 2 + '_d').stop(true, true).hide('clip');
    });


but when i want to use "for" it has problem:

JavaScript
for (var i = 1; i < 3; i++) {
            var item_d = count + '_d';
            $("#" + i).mouseenter(function () {
                $("#" + item_d).stop(true, true).show('clip');
            }).mouseleave(function () {
                $('#' + item_d).stop(true, true).hide('clip');
            });
        }


what can I do in order to use "for" instead of writing them separately?
Another question is that in Fire Fox,when my mouse over a div ,this effect execute repeatedly until mouse leave the div,this problem is just is Fire Fox,what can i do to prevent executing this effect repeatedly?
Please help me.
Thanks in advance.
Posted
Updated 19-Sep-12 2:44am
v3
Comments
DaveAuld 19-Sep-12 8:45am    
Changed language in code block from "text" to "javascript".

1 solution

Why don't you give all the same CSS class? Say, for instance:

HTML
<div id="1_d" class="div_hidden">some_content</div>
<div id="2_d" class="div_hidden">some_other_content</div>
<div id="3_d" class="div_hidden">some_other_content</div>
<div id="4_d" class="div_hidden">some_other_content</div>


Then you could with JS or even better, jQuery, toggle them all or perform any operations in bulk, like:

JavaScript
$(".div_hidden").doSomeOperation();


And in this way, it will be applied to all divs with div_hidden class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900