Getting error invalid assignment left-hand side
<p>i am suing a function in which i try to limit textarea length but on one condition i am getting the above mentioned error. Please tell me what i am doing wrong?</p>

<pre><code> function limitTextArea(element, limit) {

    var $textArea = $(element);    
    ($textArea).keypress(function(event){

        if ($textArea.val().length == limit) {
            event.preventDefault();
        } else if ($textArea.val().length &gt; limit) {

            // Maximum exceeded
            $textArea.val() = $textArea.val().substr(0, limit);
        }

    }); //end of keypress

} //end of function()
</code></pre>

<p>The line </p>

<pre><code>$textArea.val() = $textArea.val().substr(0, limit);
</code></pre>

<p>give me error that <code>invalid assignment left-hand side</code>. Why i am getting that? </p>

<p>Thanks</p>
