When the user types in +
in my input
, I would like the +
to be green
Ex: +10000 --> "+" should be green and 10000 should be black
When the user types in -
in my input
, I would like the -
to be red
Ex: -10000 --> "-" should be red and 10000 should be black
My idea was to use ::first-letter
, but I realize it doesn't work on input
Is this possible at all with css and javascript? Do I need some fancy Regex to accomplish this?
input {
font-size: 100px;
}
/* only - should be red */
input::first-letter {
color: red;
}
/* only + should be green */
input::first-letter {
color: green;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="styles.css" />
<title>Static Template</title>
</head>
<body>
<input type="text" />
</body>
</html>