Reputation: 20895
Apparently,
if (!($('#myTextArea').html()))
alert("Textarea empty");
doesn't work.
Upvotes: 0
Views: 509
Reputation: 8980
If you want to check for html, it's best to check it's length:
if (!$('#myTextArea').html().length)
However, since a textarea is a form element, it will have a value, so you should always use use .val
:
if (!$('#myTextArea').val())
alert('Textarea empty');
Upvotes: 1
Reputation: 324587
Always use val()
or the plain DOM value
property. Any other property such as innerText
, textContent
or innerHTML
(as used by jQuery's html()
method) will not update to reflect the current value of of the textarea.
For your example:
if ($('#myTextArea').val() == "") {
alert("Textarea empty");
}
Upvotes: 1
Reputation: 13579
try those maybe it helps
if (($('#myTextArea').html()==""))
alert("Textarea empty");
if (($('#myTextArea').text()==""))
alert("Textarea empty");
Upvotes: 1