Problem
By the time your code is being read, your element does not exist on the page, so the attachment of the click
never occurs.
Solution
As an alternative to what has already been suggested, if you intend to attach an click
to an element that does not yet exist yet, can attach the same to an element that is parent
, as is the case with body
or a wrapper which is present on the home page of the page.
Practical Example
Example in Jsfiddle
In the example I used setTimeout to simulate the insertion of an element in the DOM a bit after reading the page.
I don’t know yours Markup, by which remains an example assuming that your element #refresh_abertos
will be placed within a div
containing the ID #myWrapper
:
$('#myWrapper').on("click", "#refresh_abertos", function() {
alert("bubu");
});
What we’re doing here is attaching the event of click
in div#myWrapper
to be triggered when it has an effect on the #refresh_abertos
.
So you get the click
a parent element that will take effect when you click on the input element.
The solution presented makes use of jQuery .on() available as of version 1.7.
There have been other responses like this, plus @Zuul was the first to indicate using a parent div of the element, which in this case is the most ideal, so I’m accepting your answer as correct.
– Kenny Rafael