我有一个包含某个类的跨度,我想检查它是否包含它并隐藏另一个元素。
更具体地说,我有:
<span class="border">0€</span>
<div class="pop">something</div>
我尝试了该代码,但不幸的是它不起作用。
if ($(".border").html().indexOf("span") == 0€ ){
$("div[name=pop]").hide()
}
期待您的回复。
最佳答案
indexOf
函数返回索引,您无法将其与您要查找的字符串进行比较0€。
if ($(".border").html().indexOf("0€") != -1 ){
您可能需要文本而不是 html,因为该字符串不应作为 html 的一部分。
if ($(".border").text().indexOf("0€") != -1 ){
根据他添加为答案的OP评论进行编辑。
TypeError: $ is not a function
您需要添加 jQuery 的引用才能使用 jQuery 函数,例如您遇到错误的 $
。这个问题Is there a link to the “latest” jQuery library on Google APIs将显示您可以添加 jQuery
。
Is there a link to the "latest" jQuery library on Google APIs?
关于jquery - 如何查找跨度是否包含特定单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30907998/