javascript - Can't fire function on document load -
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, wrong?
i want isempty
fire on load/reload , check if input has value. if doesn't, remove removeme
class. if have value, add addme
class it.
console empty, can't figure out why isn't working properly.
update:
very odd... fire proper alert relatively if empty or not, doesn't add/remove classes. https://jsfiddle.net/37tt3x72/1/
update 02
it work, not exactly... https://jsfiddle.net/37tt3x72/2/ this
isn't working... if replace targeted element, work. question remained: why this
isn't working here?
call function document on ready function.
function isempty() { if (!$(".test").val()) { $(this).removeclass("removeme"); } else { $(this).addclass("addme"); } } $(document).ready(function(){ isempty(); });
Comments
Post a Comment