Iterate through a class of specific div which is inside another div

asp.net, html, javascript, jquery, webforms

Solution

Use this selector:

$('#PrevSelectedNews').find('.news-member-apps').each(function() { 
    // this - reference to each .news-member-apps item
})

It finds element with ID 'PrevSelectedNews' and than iterates through child elements with class 'news-member-apps'.

JQuery selector docs here.

Problem

I have a 2 divs with with inner controls having class name '.news-member-apps'. on same page. Now, i want to Loop through the class name of specific div say i want to loop through #div1 which has class name '.news-member-apps' and not the other #div2. and get the value. Note: Here i am copying the previous page DIV content to current page div i.e eg: in #PrevSelectedNews and looping through it. ``` var id = document.getElementById('<%=HiddenFieldNewsID.ClientID%>'); $('#PrevSelectedNews').load("/Default.aspx #ScrollerDiv", function () { alert(id.value); alert('Load was performed.' + $('#PrevSelectedNews')); $(".news-member-apps").each(function (k) { var NEWSID = $(this).attr("newsid"); var ID = $(this).attr("id"); if (NEWSID == id.value) { $("#" + ID).appendTo("#SelectedNews"); alert($("#" + ID) + "Found! Appending"); } }); }); ``` The #PrevSelectedNews contains all news items from previous page. Now just i want to loop through #PrevSelectedNews only where inner controls class has name '.news-member-apps'. If the HiddenFiledNewID.value matched with any of the control having class name 'PrevSelectedNews' then get the id of foind control. Help Appreciated! Thanks!

Original source