<div id="my-element"></div>
const element = document.querySelector("#my-element");
element.addEventListener("click", event => {
event.currentTarget.classList.toggle("active");
});
element.classList.remove("old-one");
element.classList.add("new-one");
element.classList.replace("old-one", "new-one");
element.classList.remove("first-class", "another-class");
element.classList.add("some-class", "another-class");
element.classList.add("some-class");
<div id="box1" class="active"></div>
<div id="box2"></div>
const box1 = document.querySelector('#box1');
const box2 = document.querySelector('#box2');
box1.classList.contains('active'); // true
box2.classList.contains('active'); // false
const options = ["Milk", "Cheese", "Water"];
let html = "<div>";
options.forEach((option, index) => {
html += '<p>Select option ${index + 1}: ${option}</p>';
});
html += `</div>`;
console.log(html);
<div>
<p>Select option 1: Milk</p>
<p>Select option 2: Cheese</p>
<p>Select option 3: Water</p>
</div>
jQuery not() 方法
not()方法返回不符合指定条件的元素。
not()方法过滤掉所有与所选条件匹配的元素,不匹配的元素将被返回。
not()方法与filter()方法相反。
CSS常用代码(一)
最新推荐文章于 2023-05-13 12:13:17 发布