Check if a DOM element matches a given selector.