Demuri Celidze Demuri Celidze - 11 months ago 60
HTML Question

How to check if input is not empty on load?

I have a code like this:

<div><input type="text" value=""></div>

How do I check with JS or jQuery if input contain any data (even from localstorage or browser cache) on load and add class to parent div if not empty?

Answer Source

Try this

//trim() is used to remove extra spaces in your input value
if($('#ver_input').val().trim() != ''){


<div><input type="text" value="" id="ver_input"></div>