使用回调函数筛选

在高级表达式不能满足你的要求,或者某个库不支持某个表达式的情况下,还可以使用回调函数来选择DOM元素。

使用YUI的YAHOO.util.Dom.getElementsBy方法,选择只包含一个图像子元素的所有锚标签。

YAHOO.util.Dom.getElementsBy(function(e){

  return(e.nodeName='A' && e.getElementsByTagName('img').length == 1)

})

 使用jquery的filter方法:

$('a').filter(function(){

  return($('img',this).length==1)

})
原文地址:https://www.cnblogs.com/cnundefined/p/getElementsBy.html