jQuery

How To Change Placeholder Color On Select Field

In this article, We learn about how to add placeholder color in the select field.

For that, we need to create one HTML

<form action-xhr="#" method="POST" class="select-form">
  <label>Select Technology</label>
  <select class="select-box">
    <option value="">Select....</option>
    <option value="css">CSS</option>
    <option value="html">HTML</option>
    <option value="worpdress">WordPress</option>
    <option value="javascript">Javascript</option>
  </select>
</form>

Add jquery for add and remove class.

Here I use the function because we need to use the same code multiple times.

Here is a small suggestion Please use the function if you need to use the same code multiple times.

jQuery( document ).ready( function($) {
    $( document ).on( 'change', 'select.select-box', function(){
        select_placeholder();
    } );
    select_placeholder();
} );

function select_placeholder() {
  jQuery( 'select.select-box' ).each( function(){
    var select_val = jQuery( this ).val();
    if( select_val != '' ) {
      jQuery( this ).removeClass( 'select-placeholder' );
    } else {
      jQuery( this ).addClass( 'select-placeholder' );
    }
  } );
}

Add this CSS

.select-box {
  width: 100%;
    color: #000;
}
.select-box.select-placeholder {
    color: #f00;
}
.select-box option {
    color: #000;
}

You can change the selected color as per your requirement.

Here is an Output:

Ankit Bavishi

I am an sr. WordPress developer and web designer and Project Manager and Specialized in developing Wordpress, Customization Theme, HTML, CSS, jQuery, Ajax, and Author at thecodehubs.

View Comments

Share
Published by
Ankit Bavishi

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago