HTML:
<input class="test removeMe" type="text">
jQuery:
$(function () {
function isEmpty() {
if (!$(".test").val()) {
$(this).removeClass("removeMe");
} else {
$(this).addClass("addMe");
}
}
isEmpty();
});
Please, tell me, where am I wrong?
I want isEmpty
to fire on load/reload and check if the input has value. If it doesn't, it will remove the removeMe
class. If it does have some value, it will add addMe
class to it.
Console is empty, I can't figure it out why this isn't working properly.
Update:
Very odd... It does fire proper alert relatively if it is empty or not, but doesn't add/remove classes. https://jsfiddle.net/37tt3x72/1/
Update 02
It does work, but not exactly...
https://jsfiddle.net/37tt3x72/2/
The this
isn't working... if replace it with the targeted element, than it will work. So the question is remained: Why this
isn't working here?