This looks like four of the 4 selection operations in the same code segment as follows
$class ("a"). Color ("green");
$class ("B"). Color ("red");
$class ("C"). Color ("green");
$class ("D"). Color ("red");
Finally, only one traversal can be achieved.
Because before there is too much attention to the problem of the selector, I do not know is not I out, we have already thought of?
Here is sample, two times to select one traversal
<body> <div class= "a" >aaaaaaaaaaaaaa</div> <div class= "a B" >bbbbbbbbbbbb</div> <div Class= "B" >cccccccccccccccc</div> </body> <script> var $class = function () {var checker = []; var updatehandler = null; var traverse = function (Node,func) {func (node); for (var i = 0; i<node.childnodes.length; i++) {func (Node.childnodes[i])}} function Update () {Traverse (docume Nt.body,function (node) {for (var i = 0; i< checker.length i++) Checker[i] (node); }); Checker = []; Updatehandler = null; function Startupdate () {if (updatehandler!==null) return; Updatehandler = settimeout (update,10); var $class = function (jpath) {var color; Checker.push (function (node) {if (typeof node.classname!= "string") return; var classes = Node.className.split ("") for (var i = 0; i < classes.length; i++) if (classes[i] = = Jpath && color) {node.style.backgroundColor = color; Break } }); return {Color:fUnction (v) {color = v; Startupdate (); "}}} $class. update = update; return $class; }(); $class ("a"). Color ("green"); $class ("B"). Color ("red"); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]