Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery detect if textarea is empty

Tags:

jquery

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');             }         }); 
like image 892
dennismonsewicz Avatar asked Nov 05 '10 15:11

dennismonsewicz


People also ask

How check textbox is empty in jQuery?

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.


2 Answers

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 } 
like image 195
Andy E Avatar answered Sep 22 '22 02:09

Andy E


if (!$.trim($("element").val())) {  } 
like image 25
IlludiumPu36 Avatar answered Sep 25 '22 02:09

IlludiumPu36