Even a task as simple as this can be complicated without jQuery at our disposal. In plain JavaScript, we could add the highlightedclass as shown in the following code snippet:
Despite its length, this solution does not handle many of the situations that jQuery takes care of for us in Listing 1.2, such as the following: • Properly respecting other window.onloadevent handlers • Acting as soon as the DOM is ready • Optimizing element retrieval and other tasks with modern DOM methods 盡管很長,但是這個解決方案依然沒有處理很多jquery在列表1.2中為我們做到的一些事情,比如下面的這些: 1、合適的處理其他的window.load事件 2、在DOM結(jié)構(gòu)準(zhǔn)備好的時候開始行動。 3、使用現(xiàn)代的DOM方法優(yōu)化元素查找和其他任務(wù)。
We can see that our jQuery-driven code is easier to write, simpler to read, and faster to execute than its plain JavaScript equivalent.