Adding an event handler to dynamically created elements can be handled as shown here:
In jQuery, how to attach events to dynamic html elements?
$('body').on('click', 'a.myclass', function() {
alert( $(this).text() );
});
However say I want to then perform an action on elements that were also added dynamically.
In the sample below $('inout.wp')s are being added after this code has run and I wish to validate them all using jQuery Validator when the handler fires:
<input type="text" name="wp_address_0" placeholder="Enter a Town, City or Postcode" id="wp_address_0" class="geocode wp">
<script>
$('body').on('click', 'a.myclass', function() {
$('input.wp').valid();
});
</script>
I though perhaps I could use .find for this:
$('body').on('click', 'a.myclass', function() {
$("#waypoints").find('input.wp').valid();
});
But it doesn't help. How can I achieve this?