MatrixNinja
MatrixNinja

Reputation: 137

Remove single attribute from element multiple times using jQuery

Here's my code so far:

<script src="http://.../jquery/1.7.1/..."></script>

<script>
$(document).ready(function(){
    $('textarea').removeAttr('style');
});
</script>

<form>
    <tr><td>
    <textarea name="Comment" cols="18" rows="4" style=""></textarea>
    </td></tr>
</form>

I put a blank style tag first to see if it works, which it does, but using .ready only removes it initially.

When you drag the corner of the textarea to enlarge it, it produces a new style="xyz"

My question is: How can I repeat this function, automatically, every time the attribute style="xyz" shows up? Basically resetting it back to the default cols="18" rows="4" size I specified.

(Sorry if this might be a simple answer, but I'm not very good with js/jQ just yet.)

Upvotes: 1

Views: 180

Answers (2)

Elisiano Petrini
Elisiano Petrini

Reputation: 602

I think @gustavohenke gave you a good tip. Nonetheless, if you want to do it with javascript you have to write a hook that execute a function (in your case remove the attribute) each time the textarea is resized.

To accomplish so, have a look at Resize event for textarea?

Upvotes: 2

gustavohenke
gustavohenke

Reputation: 41440

No need for JS to do that, just

<textarea name="Comment" cols="18" rows="4" style="resize:none"></textarea>

Upvotes: 5

Related Questions