Search code examples
javascriptgoogle-chromeuserscripts

How to change font color in an input


I want to make a user-script that changes the text color inside the google search bar:

// ==UserScript==
// @name        color change
// @namespace   google
// @include     http://*.google.com
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @version     1
// ==/UserScript==


var inputs = document.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++)
{
    if(inputs[i].type == "text")
    {
        inputs[i].text.css({'color' : 'red'});

    }
}

I pasted the following code to userscripts.org and installed it to chrome, when I visited http://google.com and started typing the text it appears black as usual where it should appear red. What did I do wrong?


Solution

  • inputs[i].style.color = 'red';
    

    userscripts are not any different than actual script in the page, you could search "change text color with js" and find this result:

    set html text color and size using javascript