Problem
By the time your code is being read, your element does not exist on the page, so the attachment of the click
event does not occur.
Solution
As an alternative to the already suggested, if you want to attach an event of click
to an element that does not yet exist, you can attach it to an element that is parent
, as is the case of body
or a wrapper that is present on the page in the initial load of the same.
Practical Example
JSFiddle Example
In the example I used setTimeout to simulate the insertion of an element in the DOM a bit after reading the page.
I do not know your markup , so here's an example assuming your #refresh_abertos
element will be placed within a div
that contains the #myWrapper
:
$('#myWrapper').on("click", "#refresh_abertos", function() {
alert("bubu");
});
What we are doing here is to attach the event of click
to div#myWrapper
to be triggered when it has effect on #refresh_abertos
element.
So you have the click
in a parent element that will take effect when you click on the element that will be introduced.
The solution presented makes use of jQuery .on () available from version 1.7.