is
用於檢測元素是否符合表達式;
<!-- 引入 ofa.js 到你的項目 -->
<script src="https://cdn.jsdelivr.net/gh/kirakiray/ofa.js/dist/ofa.min.js"></script>
<ul>
<li>I am 1</li>
<li id="target">I am target</li>
<li>I am 3</li>
</ul>
<div id="logger">logger</div>
<script>
setTimeout(() => {
const target = $("#target");
$("#logger").html = `
Is li: ${target.is('li')} <br>
Is div: ${target.is('div')} <br>
Have id: ${target.is('[id]')} <br>
Have class: ${target.is('[class]')} <br>
`;
}, 500);
</script>