Getting the current script DOM object in a (jquery) ajax request

I have a html component that includes some javascript.

The component is a file in a template engine, so it can be used

  • in the initial rendering of the whole html page
  • as stand-alone html rendered through an ajax request

The javascript should be applied to an object in the template, i.e. :

This is item 13
This is item 14

I've checked this similar question but the best answers seem to rely on the current script being the last one in the 'scripts' variable as the next ones are not loaded yet. If I append the html and js with an ajax request, it will not be the case.

To be 100% clear : the question is about getting the previous object WITHOUT reference to any specific attribute : no unique id for the tag, no random id as there is theoretically always a chance it will show up twice, no unique class attribute,as exactly the same component could be displayed in another part of the HTML document.

7
задан Community 23 May 2017 в 12:14
поделиться