IE error, the object does not support this property or method

function charCount(){ $.doTimeout('poll', 150, function(){ messageVal = $('#messageLabel textarea').val(); messageLength = messageVal.length; //IE BREAKS HERE $('#messageLength').html(messageLength + '/140') if(messageLength > 140){ $('#messageLength').not('.inv').addClass('inv') }else{ $('#messageLength.inv').removeClass('inv') } return false; }) } $('#messageLabel textarea').change(charCount).keyup(charCount); 

Gives the following error in Internet Explorer 7.0 (and possibly other versions too).

The object does not support this property or method.

Any ideas on what causes this error?

+6
source share
5 answers

If you are not using the var keyword, the IE browser looks for messageLength in the global context and finds it ... you have an element with this identifier.

An attempt to assign a number to an HTML element failed.

To solve this problem, simply declare messageLength as a local variable:

 var messageLength = messageVal.length; //IE WON'T BREAK HERE 
+23
source

Try replacing:

 messageVal = $('#messageLabel textarea').val(); 

from

 messageVal = $('#messageLabel textarea').text(); 

Hope this helps.

0
source

I think .change () has some problems in IE. Please remove it and see if it works.

Also try using .html () instead of .val ().

0
source

See a simple test . textarea does not support the value property. you can get it through a text property

0
source

I had a similar error, however, this was because I added the jQuery library to the main page, and in another place there was the same page.

0
source

Source: https://habr.com/ru/post/885805/


All Articles