python匹配元素
I was thinking about HTML elements and selectors recently. We usually start by searching for an element(s) via querySelector
/querySelectorAll
, which makes sense, but what if you want to validate that an element that wasn't specifically selected matches a given selector? For example, say you have a function which assumes the presence of classes or attributes on the elements it has been passed, and things might go wrong if the element provided doesn't fit the bill? Enter Element.matches
!
我最近在考虑HTML元素和选择器。 我们通常首先通过querySelector
/ querySelectorAll
搜索一个元素,这很有意义,但是如果您要验证未特别选择的元素与给定的选择器匹配怎么办? 例如,假设您有一个函数,它假定传递的元素上存在类或属性,并且如果提供的元素不符合要求,事情可能会出错? 输入