I have integrated a text clearing plugin from here in my project to allow users to clear the input field by clicking on an X button. However, I want to modify the code so that the X button only appears when there is text entered in the textbox. I attempted to set a condition in the JavaScript code using the return statement:
if ($('#search').val().length != 0)
but it did not yield the desired results.
Below is the snippet of code I tried:
$(document).ready(function(){
if ($('#search').val().length != 0){
$('#search').clearable();
$('.divclearable').show();
}
else{
$('.divclearable').hide();
}
});
Your assistance with this issue would be greatly appreciated.