用于选择特定项的jquery语法或正则表达式

时间:2012-01-31 16:09:25

标签: jquery html jquery-selectors

我页面中的许多HTML元素(p,a,span等)都有'title'属性。为了在这些元素上调用方法(为其标题设置样式),我可以执行以下操作:

$('[title]').method();

现在我需要阻止为所有DIV调用,其ID以特定字符串开头,例如' myDiv '。 我打赌有一个特殊的jquery选择器语法来做到这一点,但我只是无法得到它。

感谢任何帮助!

3 个答案:

答案 0 :(得分:3)

试试这个

$('[title]:not(div[id^="mydiv"])').method()

Documentation Attribute Starts With Selector

Documentation :not() Selector

更新:您也可以

进行更新
$('[title]').not('div[id^="mydiv"])').method()

Documentation .not( selector )

答案 1 :(得分:1)

$("[title]:not([id^='myDiv'])").method();

答案 2 :(得分:0)

你能使用:not selector吗?

文档:http://api.jquery.com/not-selector/