I have a bunch of text inputs that are dynamically created through a MySQL query.
At the bottom of my page I have this.. I had to use window.load instead of document.ready as the latter would not work
<script>
$(window).load(function() {
$('.<?php echo $sku; ?>').on('input', function() {
$('.'+$(this).attr('class')).val($(this).val());
});
});
It is my understanding that using .on should relate to both past and present dom objects, but this is not the case.
The (messy) html I'm currently dealing with is
<input type="text" class="mySKU18" id="inputsku" contenteditable="true" onkeydown="if (event.keyCode==13) saveToDatabase2(this,'itemnumber','mySKU18')" onClick="showEdit(this);"></input>
This is generated on the page load, and 'reset' using ajax if a button is clicked.
My issue is with the above script in relation to the html above. Both HTML's are the same on the initial page load and ajax response.
Right now my solution to get this working is to reinitiate the script at the bottom of my ajax php script.
/// my php
?>
<script>
$('.<?php echo $sku; ?>').on('input', function() {
$('.'+$(this).attr('class')).val($(this).val());
});
</script>
This works and does not provide any console errors, but obviously is not ideal. Anyone know what could be the issue and how to fix it?