Joe Allen Joe Allen - 2 years ago 73
HTML Question

Javascript error when assigning css class to textArea

I'm having a problem in Safari desktop / mobile and Internet Explorer. The error reads:

In Safari:

TypeError: Attempted to assign to readonly property.

IE Edge:
Assignment to read-only properties is not allowed in strict mode

It is happening in a function that loops through all textareas on the page and sets a specific css class on each textarea according to the character count (which changes the font-size).

My questions are:

  • Why is this error occurring when I'm just applying a css class?

  • What can I do to prevent it?

I'm using Laravel 5.4 and VueJS 2.1.10.

Here is a codepen link where I have replicated the problem. (You can see it works in Chrome and FireFox).

I will really appreciate any help. Thanks

Answer Source

Replace card.classList += 'font_normal'; with card.classList.add('font_normal'); as per the mozilla api

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download