2

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>');

2 Answers 2

3

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>');
Sign up to request clarification or add additional context in comments.

2 Comments

+1 for a good answer. I would say that @bjornd's answer is better, but both are good.
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.
1
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]");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.