Use prop() instead of attr() and removeAttr().