So i created a input using document.createElement but i just cant seem to get my mind around changing the color of the text of the placeholder i made for it!? How do i do this? ive already tried doing element.placeholder.style.color element::placeholder.style.color and more!
            Asked
            
        
        
            Active
            
        
            Viewed 2,050 times
        
    1
            
            
        - 
                    Extremely thorough answer in the linked duplicate. – Pointy Feb 25 '18 at 14:47
2 Answers
1
            
            
        You can use the ::placeholder pseudo-class in most modern browsers:
input::placeholder {
  font-weight: bold;
  font-style: italic;
  opacity: 0.5;
  color: #336699;
}<input type=text placeholder="Hello World">The pseudo-class is currently not part of a specification (well not part of a "ratified" spec) so it's often seen behind a prefix like -webkit-placeholder or -moz-placeholder. In Firefox 58 and Chrome 64 however plain ::placeholder does work.
From a userscript, you can create a new <style> element containing your rules and append that to the document body.
 
    
    
        Pointy
        
- 405,095
- 59
- 585
- 614
- 
                    As i do not have access to the css and i already know this, i will not see this as an answer, the fact that i made a userscript and want to change the color of a placeholder element – Qyther Feb 27 '18 at 14:31
- 
                    @Qyther but you *do* have access to the CSS. You can add an ordinary class to the target element and then create a new ` – Pointy Feb 27 '18 at 14:33
- 
                    
- 
                    
0
            
            
        You can add the property to ::placeholder pseudo element.Know more here
var x = (document.createElement('input'));
x.placeholder = "Test";
document.body.appendChild(x)::-webkit-input-placeholder {
  color: green;
} 
    
    
        brk
        
- 48,835
- 10
- 56
- 78
- 
                    As i do not have access to the css and i already know this, i will not see this as an answer, the fact that i made a userscript and want to change the color of a placeholder element – Qyther Feb 27 '18 at 14:31
