Let's say I have this piece of HTML code:
<a href="#">Plugin 1</a>
<a href="#" style="display:none">Plugin 1 options 1</a>
<a href="#" style="display:none">Plugin 1 options 2</a>
<a href="#">Header 2</a>
<a href="#" style="display:none">Plugin 1 options 1</a>
<div id="content"></div>
Whenever I click "Plugin 1" a table is generated inside Content div with headers containing "Plugin 1 options 1", "Plugin 1 options 2" etc. strings in them and the plugin options submenu have their "display" attribute turned to "block". I want to add an event listener to the "Plugin 1 options 1/2" elements so the page would scroll to the table header element with the same value.
How can I do that, as the elements of the table are created after the page is loaded?
Edit 1: It is not a problem of adding an event handler to not existing elements, as they are created at the very beginning. Problem here is that I want to add an event handler to existing element that will manipulate an element that will be created in the future. Here is an example from my code:
var table_element = $('th:contains("' + plugin_name + '")');
group_button.click(function () {
table_element.get(0).scrollIntoView();
});
group_button exists from the begging, where table_element is generated dynamically. Moreover, I checked whether $('th:contains("' + plugin_name + '")') is a correct selector, by passing it console when table was generated.