Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
$("#" + 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:
 
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 16-Sep-12 19:23pm
k5_ce504
Edited 19-Sep-12 2:44am
DaveAuld168.7K
v3
Comments
DaveAuld at 19-Sep-12 8:45am
   
Changed language in code block from "text" to "javascript".

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Why don't you give all the same CSS class? Say, for instance:
 
<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:
 
$(".div_hidden").doSomeOperation();
 
And in this way, it will be applied to all divs with div_hidden class
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 359
1 Richard MacCutchan 320
2 OriginalGriff 240
3 Jared Sanow 145
4 Snehasish_Nandy 115
0 Sergey Alexandrovich Kryukov 5,969
1 OriginalGriff 5,005
2 CPallini 2,473
3 Richard MacCutchan 1,547
4 Abhinav S 1,507


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100