javascript - Change the style of an input when submit is pressed -


https://jsfiddle.net/3vz45os8/7/

i've got jsfiddle want change background color of input text in specific color if word type , in 1 if word not type. it's doesn't work got no error in console. if u guys me.

this js function, log every step , didn't error:

function iscorrect() {   var test = document.getelementbyid('test').value;   if (test.value === "hello") {     test.classname = "correct"     return true;   } else {     test.classname = "incorrect"     return false;   } } 

var test = document.getelementbyid('test').value; if (test.value === "hello") { 

you're calling .value twice. take off first line, because otherwise you'll adding classname (which should camel-cased way) string value instead of input element.

here corrected code , working copy:

function iscorrect() {     var test = document.getelementbyid('test');     if (test.value === "hello") {         test.classname = "correct";         return true;     } else {         test.classname = "incorrect";         return false;     } } 

it's correctly adding class, css being overridden removed default color illustration.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -