Margin for select option in IE and chrome is not working
Posted
by
Sardor
on Stack Overflow
See other posts from Stack Overflow
or by Sardor
Published on 2012-11-16T10:31:58Z
Indexed on
2012/11/16
11:01 UTC
Read the original article
Hit count: 154
I am setting a css class to some select options in JS. This class includes margin style. It is working in the FF but not in IE and chrome.
window.onload = function() {
replace('edit-field-region-tid');
replace('edit-tid');
}
function replace(id) {
var i = 0;
var s = document.getElementById(id);
for (i; i < s.options.length; i++) {
if (find(s.options[i].text, id, i)) {
s.options[i].setAttribute("class", "sub_options");
}
}
}
function find(str, id, option_id) {
var i;
var s = document.getElementById(id);
for (i = 0; i < str.length; i++) {
if (str.charAt(i) == '-') {
s.options[option_id].text = str.cutAt(0, "");
return true;
}
}
return false;
}
String.prototype.cutAt = function(index, char) {
return this.substr(index+1, this.length);
}
And CSS:
.sub_options{
margin-left:20px;
text-indent:-2px;
}
Any ideas thanks!
© Stack Overflow or respective owner