I need to run jQuery on the last element of a specific class that is dynamically generated.
Classically I would use:
$(".class").last().on("change", function(){
something();
});
but since the .class element is generated through jQuery after the page is rendered, I have to use:
$("body").on("change", ".class", function(){
something();
});
but this entry causes the change in the first (or any) element on the page to trigger the event.
I would need to somehow include the .last() function into the second selector.
Simply: I have an input on the page that is empty, when a change is made to it, a copy of this input with empty content should be generated and inserted after the first input. If this one is filled, another one is generated. Currently (using $("body").on("change",...) the next input is generated again and again even if I change the first input field X times.
Thanks everyone
You can ask
$("body").on("change", ".class", function(){
if($(this).is(':last-child')) {
//something
}
});