Click here to Skip to main content
15,888,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello every body
i generate some div in loop in c# (i dont know the number of div because i fetch from db) and i put dynamic name for them like show1,show2,show3 ... show n.
and i put this script for all of them => display:none;
and i dont know how to understand how many 'show x' i have! =>for end loop condition

i want to fadeIn them one by one not at all in jquery.
please help me.

What I have tried:

$(document).ready(function () {
$('#show1').fadeIn();
});
Posted
Updated 12-Jul-16 4:09am
Comments
Suvendu Shekhar Giri 12-Jul-16 6:53am    
Just a rough idea.
Assign them with same css class and iterate between them based on the class.
Search how to iterate between elements with same class in google for more info.

JavaScript
$(document).ready(function () {
    // id^=show means all ids that begin with show
    $("[id^=show]").each(function() {
        $(this).fadeIn();
    });
});
 
Share this answer
 
try using Window setInterval() Method[^] to see the transition in real time ( load one after another )

HTML
<html>
<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

    <style>
        .divclass {
            height: 100px;
            width: 200px;
            background-color: green;
            border: 5px solid red;
            display: none;
        }
    </style>

    <script>
        $(document).ready(function () {
            var divs = $("[id^=show]");
            var i = 0;
            var loop = window.setInterval(function () {
                i++;
                $(divs[i]).fadeIn(1000);
                if (i == divs.length)
                    clearInterval(loop);
            }, 1000);
        });

    </script> 
</head>
<body>

    <div id="show1" class="divclass">show1</div> <br />
    <div id="show2" class="divclass">show2</div> <br />
    <div id="show3" class="divclass">show3</div> <br />
    <div id="show4" class="divclass">show4</div> <br />
    <div id="show5" class="divclass">show5</div> <br /> 

</body>
</html>


demo: Edit fiddle - JSFiddle[^]
 
Share this answer
 
v2

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