I have written a code which works on change but now I am also looking into page load and anything happens on the input field which has that specific class like blur or oninput ot paste or whatever, it should trigger the code and the moment the value is more than 0.00, it should run the code and display the label to block
Here is my code
document.addEventListener('readystatechange', function(e) {
switch (e.target.readyState) {
case "complete":
$('.totalsTeal').trigger('change');
break;
}
});
and here is how the change event is written
$(document).on('change focus blur', '.totalsTeal', function() {
let self = $(this);
let day = self.attr('data-name');
if (self.val() === "0.00") {
$('#w1_' + day).parent().find('label').css('display', 'none');
} else {
$('#w1_' + day).parent().find('label').css('display', 'block');
}
});
the above code shows what I have done and what I am trying to write
2
Answers
Use the
input
event, which triggers when an input field receives any input.This is really a trivial operation that really isn’t made that much simpler with JQuery. Also, you should be using CSS classes instead of working with inline styles as inline styles are more difficult to override and can lead to duplication of code.
Place the following code within a
<script>
element and place that element just prior to the closingbody
tag and you’re done.Please be consistent – use DOM OR jQuery, please do not mix.
jQuery
Vanilla JS