Singaravelan
Singaravelan

Reputation: 839

Change the Dropdown width using Jquery

In my form has four DropDown list controls, I want to set width for one of the control as 200px using Jquery. Because this control's value dynamically change and dont know how length is. How to do this? with IE8.

Upvotes: 0

Views: 4808

Answers (4)

DAC84
DAC84

Reputation: 1274

If you don't know the length of the options then you could just set width: auto; and let it size accordingly. But if you do need to set it to 200px though use:

$('your-selector').css("width", 200);

Upvotes: 0

chridam
chridam

Reputation: 103365

One option is to use width

$('#selectId').width(200);

or CSS:

$('#selectId').css({'width': 200});

Upvotes: 1

Felix
Felix

Reputation: 38102

You can use change() event to keep track when the value of your select has been changed and use width() to set the width of it:

$('#dropDownId').change(function() {
    $(this).width(200);
}).change();

Upvotes: 0

Rey Libutan
Rey Libutan

Reputation: 5314

It will help if you post your HTML but you can do it like this:

$("#idOfMyDropdown").css("width", "200px");

Upvotes: 0

Related Questions