John Stab John Stab - 5 months ago 7
Javascript Question

JQuery - How to get the THIS for inner EACH

I have inner each like

$('a[id^="Page"]').each(function () {
if ($(this).attr("id") == pageId) {
$('[id="' + pageId + '"]"').each(function () {


How to access the current element since THIS is from previous EACH?

Thanks!

Answer

you can use the callback's second argument to get the element like so:

 $('a[id^="Page"]').each(function (index, element) {
         if ($(element).attr("id") == pageId) {
                  $('[id="' + pageId + '"]"').each(function (j, pageElment) {
                       console.log(element);
                       console.log(pageElment);
                  });
         }
 });
Comments