how to loop over the child divs of a div and get the ids of the child divs?

后端 未结 6 1682
你的背包
你的背包 2020-12-16 12:20

I have a div with id test

and through the foreach loop I am creating some inner divs inside the test div. So it becomes like this.

6条回答
  •  感情败类
    2020-12-16 12:57

    What you are trying to do is loop through the direct-descendant divs of the #test div; you would do this using the > descendant selector, and the jQuery .each() iterator. You can also use the jQuery .css() and .attr() methods for styling and retrieving the id respectively.

    $("#test > div").each(function(index){
        var id = $(this).attr("id");
        $(this).css(/* apply styles */);
    });
    

提交回复
热议问题