Áno, JavaScript vkladám pomocou tlačidla pre JavaScript, ktoré obalí kód do [code lang="js"][/code] (formátovanie sa dá vyskúšať pri náhľade).
Tvoj kód funguje aj v IE.
Doplním ešte do minulého kódu JavaScript:
var helper =
{
addClass: function (el, className)
{
this.removeClass (el, className);
el.className += " " + className;
},
removeClass: function (el, className)
{
var cls = el.className.split (/\s+/);
var ar = [];
for (var i = cls.length; i > 0;)
if (cls [--i] != className)
ar [ar.length] = cls [i];
el.className = ar.join (" ");
},
hasClass: function (el, className)
{
var cls = el.className.split (/\s+/);
for (var i = cls.length; i > 0;)
if (cls [--i] == className)
return true;
return false;
}
};
CSS:
.invalid { background: red; }
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test</title>
<link href="subor-so-stylmi.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="subor-s-javascriptom.js></script>
<body>
<form id="editor" action="">
<p>
<input type="text" name="a" value="13" class="validate" />
</p>
</form>
</body>
</html>