0

I have content on the page both dynamically created after ajax request and content that were pre loaded on the page refresh.

When click a anchor tag i want to find if this particular anchor tag was created dynamically or not.

Though i solved this issue by using some logic but it would have been much more easy if i could do so in some other particular way

I did a lot of google but found known solution for this

Selvesan Malakar
  • 511
  • 2
  • 7
  • 20

1 Answers1

0

You could assign a class to each dynamically created <a> and then write some JavaScript/JQuery to check if that class exists.

<a href='#' id='static'>Static</a>
<a href='#' class='ajax-dynamic' id='dynamic-1'>Dynamic 1</a>
<a href='#' class='ajax-dynamic' id='dynamic-2'>Dynamic 2</a>

JavaScript/jQuery

$('a').off('click').on('click', function(e) {
   e.preventDefault();

   if ($(this).hasClass('ajax-dynamic')) {
     alert('anchor created dynmically');
   }
})

Fiddle: https://jsfiddle.net/oq1zz3nj/3/

LeDoc
  • 935
  • 2
  • 12
  • 24