0

I am trying to change the height of my textarea. Zurb's Foundation has already defined a height of 5rem !important.

Now, when I try to change my height using jQuery, it doesn't change. I tried:

$('textarea').height('500px')
$('textarea').css('height', '500px', 'important);

and nothing works. The CSS of any other property does change with .css(). What can I do?

Kousha
  • 32,871
  • 51
  • 172
  • 296

5 Answers5

1

If 5rem !important is set as inline style then it has the highest precedence then you can not override it by any CSS rule. You have to update the inline style then. Try this:

$('textarea').get(0).style.setProperty('height','200px','important');

From the MDN Docs

CSSStyleDeclaration.setProperty()

No return. Example: styleObj.setProperty('color', 'red', 'important')

Update:

Please read this Answer: Apply !important CSS style using jQuery You will find really useful info there..

Happy Coding!!

Community
  • 1
  • 1
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
0
$('textarea').attr('style', 'height: 500px !important');
RGS
  • 5,131
  • 6
  • 37
  • 65
0

Demo

You can use css - but it does not support Priority field.

Following is the correct syntax:

$('textarea').css('height','500px')

Or if you need important, you can use inline style or a class.

Demo : Add Class

.areaHeight{
    height : 500px !important;
}

$('textarea').addClass('areaHeight')

There are other not-so-viable options : cssText

Community
  • 1
  • 1
Shaunak D
  • 20,588
  • 10
  • 46
  • 79
0

try this

<textarea id="textareaid"> </textarea>
$('#textareaid').css('height', '500px');
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
krishna
  • 98
  • 5
  • Welcome to SO!! I see this is a new answer. Please try to read the existing answers and exact question. Your answer does not answer the OP's question. – Sachin Jain Jun 24 '14 at 04:18
0

Try using anyone of these to set the height

Type:  1
 $("textareaid").height("600")

Type:  2
 $("textareaid").css("height","400px")

Make sure ur script is called after the dom element gets created

Unknownman
  • 473
  • 3
  • 9