def only_child(of_type)
      lambda do |element|
        # Element must be inside parent element.
        return false unless element.parent and element.parent.tag?
        name = of_type ? element.name : nil
        other = false
        for child in element.parent.children
          # Skip text nodes/comments.
          if child.tag? and (name == nil or child.name == name)
            unless child.equal?(element)
              other = true
              break
            end
          end
        end
        !other
      end
    end
def only_child(of_type)
      lambda do |element|
        # Element must be inside parent element.
        return false unless element.parent and element.parent.tag?
        name = of_type ? element.name : nil
        other = false
        for child in element.parent.children
          # Skip text nodes/comments.
          if child.tag? and (name == nil or child.name == name)
            unless child.equal?(element)
              other = true
              break
            end
          end
        end
        !other
      end
    end
Creates a only child lambda. Pass +of-type+ to only look at
 elements of its type.