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 } } }
// 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-- } } }