0

I have a code like this

<div id="div1"></div>
<hr id="line1" color="#0f0" size="2" width="50px">
<div id="div2" ></div><br>
<hr id="line2" color="#0f0" size="2" width="50px" style="display:none;" >
<div id="div3" ></div><br>
<hr id="line3" color="#0f0" size="2" width="3.5%" style="display:none;" >
<div id="div4" ></div><br>
<hr id="line4" color="#0f0" size="2" width="3.5%" style="display:none;" >
<div id="div5" ></div><br>
<hr id="line5" color="#0f0" size="2" width="3.5%" style="display:none;">

Can i use this coding in any looping statement with the uses of script or jquery.

Dineshkani
  • 2,586
  • 6
  • 27
  • 43

4 Answers4

2

Yes. Use a HTML template.

Try JQuery Tmpl

KnockoutJS talks about Templates in detail on their website.

This SO answer also mentions templates and several ways of using them.

Here's how it looks in a fiddle

http://jsfiddle.net/YYfmu/

Community
  • 1
  • 1
deltree
  • 3,516
  • 1
  • 25
  • 47
1

Yes, you can loop through the divs for example this way:

for(var i = 0; i < 5; i++)
    $("#div"+i).some_method();
cek-cek
  • 480
  • 6
  • 11
1

working jsFiddle

you can loop using div hr if you have any thing in the div

or use hr to loop

Mina Gabriel
  • 17,138
  • 23
  • 89
  • 118
0

I found the answer.

for(var i =1; i<= 5; i++)
{
$('#target').append('<div id="div'+ i +'" </div><br>')
$('#target').append('<hr id=line'+i+'" color="#0f0" size="2" width="50px" style="display:none;">')
}
Dineshkani
  • 2,586
  • 6
  • 27
  • 43
  • 1
    not at all what I thought you were going for, though apparently some others here understood it. – deltree Jul 11 '12 at 12:37