jQuery to Native JavaScript comparison

A comparison of a simple script which replaces class "old" with class "new" on any selected div elements.

Native JavaScript

var el = document.getElementByTagName("div");
for ( var = i; i < el.length; i++ ) {
  if( el&#91;i&#93;.class === 'old' ) {
    el&#91;i&#93;.class = 'new';
  }
}
&#91;/snippet&#93;

<h3>jQuery</h3>

[snippet type="js"]
$("div").removeClass("old").addClass("new");

Comments are closed.