Using node.contains and if/ternary to act upon dom elements if they exist