html - How to change the colour of placeholder using javascript? -


i want change colour of placeholder after calling mobilevalidate().

<input type="text" class="form-control" name="inputmobile" id="mobile"    placeholder="enter mobile number" onblur="mobilevalidate()"required> 

javascript function is

function mobilevalidate(){      var x = document.getelementbyid("mobile");          if ((x.value).match(re)){             alert("mobile number valid");         }         else{              alert("mobile no not valid");             x.value="";             x.placeholder.style.color="red";         }  } 

you can't modify pseudo-selectors javascript. you'll have modify existing element.

if possible, make class:

.your-class::-webkit-input-placeholder {     color: #b2cde0  } 

and add element:

$('input').addclass('your-class'); 

or if want use pure js, this:

x.classlist.add('your-class'); 

Comments