예제 #1
0
파일: app.go 프로젝트: influx6/examples
// addClass adds class to the given element. It retains any other classes that
// the element may have.
func addClass(el dom.Element, class string) {
	newClasses := class
	if oldClasses := el.GetAttribute("class"); oldClasses != "" {
		newClasses = oldClasses + " " + class
	}
	el.SetAttribute("class", newClasses)
}
예제 #2
0
파일: app.go 프로젝트: influx6/examples
// removeClass removes the given class from the element it retains any other
// classes that the element may have.
func removeClass(el dom.Element, class string) {
	oldClasses := el.GetAttribute("class")
	if oldClasses == class {
		// The only class present was the one we want to remove. Remove the class
		// attribute entirely.
		el.RemoveAttribute("class")
	}
	classList := strings.Split(oldClasses, " ")
	for i, currentClass := range classList {
		if currentClass == class {
			newClassList := append(classList[:i], classList[i+1:]...)
			el.SetAttribute("class", strings.Join(newClassList, " "))
		}
	}
}