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?

7
  • Is the already defined style 5rem !important an inline style ? Commented Jun 24, 2014 at 4:06
  • Don't see a problem:jsfiddle.net/U75uW Can you check if some other style definition is over ridding your jQuery style Commented Jun 24, 2014 at 4:07
  • @blunderboy, no it is defined in the foundation's css file. Commented Jun 24, 2014 at 4:08
  • .css('height', '500px', '!important'); - missing quotes in important Commented Jun 24, 2014 at 4:09
  • 2
    @ShaunakD, no you do not need the ! when you use the jQuery: .css(name, value, priority). Commented Jun 24, 2014 at 4:12

5 Answers 5

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!!

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0
$('textarea').attr('style', 'height: 500px !important');

2 Comments

Alright this worked thanks! But why can't I just use .css()??
I won't prefer doing this because it will over-ride my entire inline style.
0

try this

<textarea id="textareaid"> </textarea>
$('#textareaid').css('height', '500px');

1 Comment

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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.