ARTLoe ARTLoe - 8 days ago 3
jQuery Question

Rails 4 - Simple Form - Jquery - How to add a class to an option in a selectbox

I am so confused - your help would be much appreciated. Could one kindly tell me how to add a class to a specific option in a select box.

As per the image, i would like to add a class only to the option:

<option value="4">both X men & X women</option>
but i am unsure how


<%= simple_form_for [@user, @social] do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.association :category_quantitygender, collection: CategoryQuantitygender.all, prompt: "select a category", label: "Quantity Gender Selection", input_html: { class: 'category_select' } %>

<div class="form-actions">
<%= f.button :submit %>
<% end %>

i tried the below but no luck:

$(document).ready(function() {
$('#social_category_quantitygender_id').addClass($('here').val() == 4));

enter image description here


Try this ......


Hope this will work for you.............