尝试通过将类应用于非常特定的字符组来减少文档中的 HTML。在我的示例中,它是一组星号,它们在文档中显示为 ** 并且它们包含的代码是
<span class="asterisk">**</span>
但是页面上有超过 50 个实例。所以我正在寻找一种方法将类动态添加到定义的组中,在这种情况下**
到目前为止,提出的最有效的解决方案是
<script>
$("span:contains('**')").addClass("asterisk");
</script>
这减少了所需的代码量并将其带到<span>**</span>
在下面的示例中,如果我希望所有 '**' 都表示食品并获得我可以做的课程
<span>**</span>Indicates food related word
<p>Intelligentsia high life shoreditch keffiyeh skateboard, hoodie master cleanse helvetica. Fanny pack <span>**</span>raw denim street art, wes anderson gentrify lomo lo-fi. </p>
<p>Selfies typewriter you probably haven't heard of them <span>**</span>small batch street art, cliche raw denim try-hard sartorial cardigan pitchfork. Forage flannel portland, small batch before they sold out +1 post-ironic <span>**</span>PBR skateboard mixtape fap try-hard banjo bicycle rights. Vinyl banksy banjo, <span>**</span>gastropub <span>**</span>four loko art party <span>**</span>food truck next level.</p>
看看这怎么会重复?所以我的意图是在我想要选择的内容旁边输入“**”。然后该类被动态添加到定义的字符组中。
<p>**Chambray letterpress **kale **chips **high life 90's wolf yr semiotics mcsweeney's biodiesel, flannel fixie retro.</p>
<p>Meh wayfarers fap scenester retro single-origin **coffee, cliche craft **beer 8-bit lo-fi selvage yr mixtape 90's.</p>
可以使用一些帮助来缩小从这里到哪里去完成这个。