Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  163] [ 1]  / answers: 1 / hits: 25443  / 9 Years ago, fri, may 8, 2015, 12:00:00

I want to change the colour of this 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 is valid);
}
else{

alert(mobile no is not valid);
x.value=;
x.placeholder.style.color=red;
}

}

More From » html

 Answers
1

You can't really modify pseudo-selectors with JavaScript. You'll have to modify an existing a element.



If possible, make a class:



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


And add it to the element:



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


Or if you want to use pure JS, do this:



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

[#66683] Wednesday, May 6, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
;