Jquery Select Box And Loop Help
Thanks for reading. I'm a bit new to jQuery, and am trying to make a script I can include in all my websites to solve a problem that always drives me crazy... The problem: Select b
Solution 1:
To modify each select, try this:
$('select').each(function(){
$('option', this).each(function() {
// your normalizing script here
})
});
The second parameter (this) on the second jQuery call scopes the selecter ('option'), so it is essentially 'all option elements within this select'. You can think of that second parameter defaulting to 'document' if it's not supplied.
Solution 2:
I was able to replicate your results for all selects on a page in IE7 using this code, which I find much simpler than the span method you are using, but you can replace the "resize" function with whatever code suits your needs.
functionresize(selectId, size){
var objSelect = document.getElementById(selectId);
var maxlength = 0;
if(objSelect){
if(size){
objSelect.style.width = size;
} else {
for (var i=0; i< objSelect.options.length; i++){
if (objSelect[i].text.length > maxlength){
maxlength = objSelect[i].text.length;
}
}
objSelect.style.width = maxlength * 9;
}
}
}
$(document).ready(function(){
$("select").focus(function(){
resize($(this).attr("id"));
});
$("select").blur(function(){
resize($(this).attr("id"), 40);
});
});
Post a Comment for "Jquery Select Box And Loop Help"