我需要查找和迭代所有具有特定属性的子元素。以下代码在jquery 1.2.6中运行正常,但在1.3.2中抛出异常
$(parentElement).find('*[@someAttributeName]').each(function(index){ doSomething(this); });
什么是正确的方法来实现呢?
解决方法
只是摆脱@,我相信。
$(parentElement).find('[someAttributeName]').each(function(index){ doSomething(this); });
从jQuery selector文档:
Note: In jQuery 1.3 [@attr] style selectors were removed (they were prevIoUsly deprecated in jQuery 1.2). Simply remove the ‘@’ symbol from your selectors in order to make them work again.