TonyR Posted April 8, 2019 Share Posted April 8, 2019 Hi I have managed to get a clear button working in an input field but I do not know how to get to appear only when there is text in the field. You can see what I have at the moment here: https://codepen.io/TonyRuttle/pen/EJNyVN I am not sure if this is a CSS issue but a JS topic but I have added this topic in the CSS category. Tony Link to comment Share on other sites More sharing options...
requinix Posted April 8, 2019 Share Posted April 8, 2019 If you keep the input as required then you can use the :valid/invalid CSS selectors. input:invalid + #clear { visibility: hidden; } Separately, you shouldn't make the clear button use an ID because then you can't have more than one on a page. At least 90% of the time, if you're thinking of using an ID you should probably use a class instead. Link to comment Share on other sites More sharing options...
TonyR Posted April 8, 2019 Author Share Posted April 8, 2019 Thank you requinix. This is working perfectly. Duly noted regarding the id/class. I have edited the above link to add your changes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.