I want to add some divs using jQuery in a main div called activity-div and then add a list to every div. But list items are not same for every div. So i think i need to give id to every div and then using that id i can access div and put list items in that div. i am using this jQuery code:
for (i=0;i<obj.length;i++){
$('#activity-div').append('<div class="area" id="area"'+i+'><h3><a href="#">'+obj[i].name+'</a></h3></div>');
}
Lets suppose obj.length is 5. Then 5 divs will be added. and their id’s will be area1, area2, area3, area4 and area5. My question is how can i get these divs by id using a loop. I know that a div can be accessed using this:
('#area1').append('<ul><li></li></ul>');
i want to access all divs i created using the loop and then add list in that. How can i do that? what will be the syntax for that? I tried
('#area'+i).append('<ul><li></li></ul>');
but it didn’t work. I am new to jQuery and couldn’t find any online help. Thanks in advance.
$('#area'+i).append();should work!You do have an error in your code:
should be: