Steven Jones
Steven Jones

Reputation: 694

Change the size of input with jquery

I have the following input:

<input id="input_2_2" 
       class="medium" 
       type="file" 
       tabindex="4" 
       size="20" 
       value="" 
       name="input_2">

I don't have access to the HTML therefore I would like to apply jQuery to change the size to "60".

Please can someone help?

Upvotes: 6

Views: 30450

Answers (5)

Sisalik
Sisalik

Reputation: 82

I used .prop

$('#input_2_2').prop('size',60);

As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

Upvotes: 0

WojtekT
WojtekT

Reputation: 4775

You can use the .attr method:

$('#input_2_2').attr('size',60);

Upvotes: 16

ayyp
ayyp

Reputation: 6598

$("input_2_2").attr("size", "60");

Upvotes: 2

Ricardo Binns
Ricardo Binns

Reputation: 3246

use attr();

like this:

<input id="input_2_2" class="medium" type="file" tabindex="4" size="20" value="" name="input_2">

$("#input_2_2").attr("size","60");

or, you can just set the width of the element, in my opinion it's better.

Upvotes: 1

Tom O
Tom O

Reputation: 1800

Use this:

$("#input_2_2").attr("size", "60");

I believe that should work..

Upvotes: 2

Related Questions