This may be a six year old post, but I still found it helpful! I just spent an hour with Chat-GPT and couldn't debug my problem. Finally I did an "old school" stack overflow search and found this. I had the exact same problem. I was calling element.clear() in the wrong place and shooting myself in the foot. Thank you for your post!