admin管理员组文章数量:1389754
I'm looking for a way to detect wheter my label object has a "-" character in it.
<label>blabla</label> -> has not
<label>bla-bla</label> -> has
Im not to familiar with regular expressions.
I'm looking for a way to detect wheter my label object has a "-" character in it.
<label>blabla</label> -> has not
<label>bla-bla</label> -> has
Im not to familiar with regular expressions.
Share Improve this question edited May 31, 2012 at 16:58 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Apr 1, 2011 at 15:33 MarkusMarkus 4,0388 gold badges50 silver badges65 bronze badges 1- 3 If you are trying to find the labels that contain a "-" then you can use the inbuilt contains selector. i.e: var labels = $("label:contains(-)"); – Chandu Commented Apr 1, 2011 at 15:41
1 Answer
Reset to default 6First get the contents of the label, then use the regex /-/
.
> "blabla".match(/-/)
> null
> "bla-bla".match(/-/)
> ["-"]
You don't even need a regex here, you can use indexOf
:
> "blabla".indexOf('-')
> -1
> "bla-bla".indexOf('-')
> 3
If you just want to select the label
element if it contains a "-", you could use:
$('label:contains("-")')
It depends on what you are trying to do.
本文标签: javascriptjquery how to find a single character in htmlStack Overflow
版权声明:本文标题:javascript - jquery: how to find a single character in html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744632325a2616615.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论