Demuri Celidze Demuri Celidze - 1 year ago 104
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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download