Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm looking to style the radio and checkbox form elements by replacing the form element with an image. I want to be able to style the checkbox and have jquery make an array of the values.

Something like this:

input[type=checkbox] {
  width:13px;height:13px;
  /*.css() can't take the shorhand background property I don't think*/
  background-image:url(assets/img/bg_form_checkbox.gif);
  background-repeat:no-repeat;
  background-position:50% 50%;
  position:relative;
}

Is there a way to store the css values in an array and iterate through them and assign them to a span?

$("input[type=checkbox]").after('<span style="'+cssValuesHere+'"></span>');
share|improve this question
add comment (requires an account with 50 reputation)

2 Answers

up vote 3 down vote accepted

Try to use this:

.css_class {
  width:13px;height:13px;
  /*.css() can't take the shorhand background property I don't think*/
  background-image:url(assets/img/bg_form_checkbox.gif);
  background-repeat:no-repeat;
  background-position:50% 50%;
  position:relative;
}

$(".css_class").after('<span class="css_class"></span>');
share|improve this answer
+1 for a good answer. I would say that @bjornd's answer is better, but both are good. – Spudley Jun 2 '11 at 16:25
Thanks, I ended up using something similar to this. I named the classes .checkbox, .radio, and .select and had jQuery apply the proper class to a span that was replacing whatever input type needed styling. – Ryan Jun 3 '11 at 15:21
add comment (requires an account with 50 reputation)
var cssValues = {
    width:'13px',
    height:'13px',
    background-image: 'url(assets/img/bg_form_checkbox.gif)',
    background-repeat: 'no-repeat',
    background-position: '50% 50%',
    position:' relative'
}

$('<span/>').css(cssValues).insertAfter("input[type=checkbox]");
share|improve this answer
1  
+1 for the best answer. – Spudley Jun 2 '11 at 16:25
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.