kig på
js setAttribute eller
js className<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
.style1{
border-width:4px;
border-color:#FF0000;
}
.style2{
border-width:4px;
border-color:#0000FF;
}
</style>
<script type="text/javascript">
function check(elm){
// document.getElementById("idElement").setAttribute("class", "myClass");
// document.getElementById("idElement").className = "myClass";
/* lang form
if(elm.value==""){
elm.setAttribute("class", "style1");
}
else{
elm.setAttribute("class", "style2");
}
*/
// kort form
var cl=(elm.value=="")? "style1" : "style2";
elm.setAttribute("class", cl);
}
</script>
</head>
<body>
<input type="text" placeholder="Type some text" onblur="check(this)" >
</body>
</html>