1
$(this).css("background-color", "red");

For normal input I style the background RED within my for each input loop which works fine.

But when its a select it doesnt seem to work. The jquery mobile select image still stays the same!

Im using JQuery + JQuery Mobile.

How do i force it to change? Even if its just adding a border?

1
  • Have you looked if the select has a background-image set? If there is a background-image you can set the background-color how much you want, you will not see it as long as the image is not cleared Commented Jul 19, 2012 at 11:52

3 Answers 3

1

You could easily override the styles for every select menus in CSS:

div.ui-select span.ui-btn-inner {
    border: 1px solid red;
    color: red;
    text-align: right;    
}

.. or if you want to stick to jQuery:

$('.ui-select span.ui-btn-inner').css('background-color', 'blue');​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

.. to customize a specific select menu, give your select element an id and then to select it with jQuery you'll need to append -button to the id. That's due to the fact that jQuery Mobile creates multiple elements that you might not know of. So, if you'll give your select menu an id custom-id and you want to change its background color, your jQuery should look like this:

$('.ui-select #custom-id-button span.ui-btn-inner').css('background-color', 'green');

.. and same in CSS:

div.ui-select #custom-id-button span.ui-btn-inner {
    text-align: left;    
}

Updated JSFiddle
http://jsfiddle.net/5Bkx9/6/

Sign up to request clarification or add additional context in comments.

3 Comments

Like this answer alot, but how would i do it for only certain selects rather than them all? Ive tryed $('#' + id).addClass('customSelect') and the customselect class is the same as your code above but with backgroud color, as your code ads it to all selects
okey, i updated my answer and jsfiddle, let me know if you'll need any assistance
Hey, What a great piece of code, the problem im having now is this: ive loaded the dom, and when i click a button i want to be able to style the select css, now this doesnt work with our code if i add class or add css and ive tried doing the select element trigger create and still nothing, all help would be very much appreciated , thanks
0

Check what this is in your execution context. Remember that this can be different things for same exact method, depending on target of invocation. It's better to select it explicitly using a selector.

If this is not the problem, check if you have this field styled with !important directive added after background color.

To get better analysis of your problem you'll have to give us more information, best replicated in jsfiddle.

1 Comment

Tried that, i cant important to JS fiddle as this project is way to big
0

My solution for this was

$(element).parent().addClass("inputRequired");

Getting the parent of the element(which is the select tag) and adding the required class to the DIV instead.

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.