I am trying to determine if a textarea is empty if a user deletes what is already pre-populated in the textarea using jQuery.
Anyway to do this?
This is what I have and its not working
$(textarea).live('change', function(){ if($(this).val().length == 0) { $(submitButtonClass).addClass('disabled_button'); $(submitButtonClass).removeClass('transSubmit'); } else { $('.disabled_button').addClass('transSubmit').css({ 'cursor':'pointer' }).removeClass('disabled_button'); } });
To check if the input text box is empty using jQuery, you can use the . val() method. It returns the value of a form element and undefined on an empty collection.
if (!$("#myTextArea").val()) { // textarea is empty }
You can also use $.trim
to make sure the element doesn't contain only white-space:
if (!$.trim($("#myTextArea").val())) { // textarea is empty or contains only white-space }
if (!$.trim($("element").val())) { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With