Click here to Skip to main content
13,145,068 members (52,145 online)
Rate this:
Please Sign up or sign in to vote.
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
Updated 19-Sep-12 2:44am
DaveAuld 19-Sep-12 8:45am
Changed language in code block from "text" to "javascript".

1 solution

Rate this: bad
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:


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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2017
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