abstract some common DOM code