JavaScript & jQuery - Chapter 5: Document Object Model - Remove Attribute
List
Buy groceries
- fresh figs
- pine nuts
- honey
- balsamic vinegar
以上为HTML代码,以下为JavaScript代码。
书上说“这段脚本检查了选中元素是否包含class属性,如果包含,就把它移除掉。”按我的理解应该移除第一个啊,怎么会移除最后一个呢?是我理解的不对?
var firstItem = document.getElementById('one'); // Get the first item
if (firstItem.hasAttribute('class')) { // If it has a class attribute
firstItem.removeAttribute('class'); // Remove its class attribute
}