0

Please check this code, and tell me what I'm missing, I just want to change the color of placeholder after clicking on a button. but I can't figure it out what's wrong.

function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}

$(".submit_btn").click(function()
{
    if($(".txt_style").text()!="")
    {
    alert(makeid());
    }
    else
    {
    $(".txt_style").attr("placeholder", "Please enter your email address");
    $('input::-webkit-input-placeholder').css("color", "red");
    }
});
Rohit Gautam
  • 312
  • 2
  • 17
  • 1
    missing `.` in `$("txt_style").text()` or just typo? – guradio Nov 06 '17 at 05:32
  • Please check the last line. after make_id(); $('input::-webkit-input-placeholder').css("color", "red"); yes . is missing but i don't want to alert tht fuction. just check last line which is not working – Rohit Gautam Nov 06 '17 at 05:33

1 Answers1

3

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');
Abhishek Gupta
  • 109
  • 1
  • 7
  • @Abhsihek Gupta, Smart think. this works for me thanks, I didn't know that we can't modify pseudo-selectors. it's clear for me now – Rohit Gautam Nov 06 '17 at 05:44