示例#1
0
文件: htmlutil.go 项目: nf/htmlclean
func RemoveAttr(n *html.Node, key string) {
	for i, a := range n.Attr {
		if a.Key == key {
			copy(n.Attr[i:], n.Attr[i+1:])
			n.Attr = n.Attr[:len(n.Attr)-1]
			return
		}
	}
}
示例#2
0
文件: mutate.go 项目: dunmatt/goquery
// removes an attribute from a node
func removeAttr(node *html.Node, attrName string) {
	for i := 0; i < len(node.Attr); i++ {
		if node.Attr[i].Key == attrName {
			last := len(node.Attr) - 1
			node.Attr[i] = node.Attr[last] // overwrite the target with the last attribute
			node.Attr = node.Attr[:last]   // then slice off the last attribute
			i--
		}
	}
}