simple singularities

prototype

Filed under: programming — fri13th July 27, 2006 @ 6:05 pm

everybody says prototype is an innovative tool in javascript. but sometimes using dom & css instead document id is more fast and clean. i.e. when manipulating multiple check values from input tag, and change their class, in prototype, usually like this..

<input id="x1">, <input id="x2">…
i =1;
while () {
 if ($("x" + i) == null) break;
 if ($("x" + i).checked == true) 
  $("x" + i).className="another";
 i++;
}

but this case is more efficient, because the code is more compact and intuitive and you don’t have to care about id, and its length.
<input> <input>
tags = document.getElementsByTagName(‘input’) ;
for (int i; i < tags.length; i++)
 if (tags[i].checked == true)
  tags[i].className="another";

how do you think about that? (maybe there are better ways than me. i’m not good at prototype technics.)

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment