我想根据“category-lifestyle”
或“category-magazine”
等特定前缀提取类。
HTML 标记如下所示:
<article id="post-361" class="et_pb_post post-361 post type-post status-publish format-standard has-post-thumbnail hentry category-lifestyle category-magazine">
Post content...
</article>
最佳答案
您可以使用以下选择器:
console.log(
document.querySelectorAll("article[class*='category-lifestyle']")[0].innerHTML
);
关于javascript - 使用 JavaScript/jQuery 获取以特定前缀开头的所有类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44352686/