It is necessary that when inputting input number 0 , an element with the class warning

warning изначально ему задан display: none

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input class="price" type="text"> <p class="warning">Неверное значение</p> 

  • one
    And what kind of record is $(".price:text").val(function()... ? Where did you see this? - Stepan Kasyanenko
  • Yes, I already knew that nonsense - RavenTheX

1 answer 1

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> <input class="price" type="text"> <p class="warning" style="display:none;">Неверное значение</p> <script> $('.price').on('keyup',function(){ if($(this).val()==0){ $('.warning').css("display","block"); }else{ $('.warning').css("display","none"); } }); </script> 

UPD

Judging by the fact that the field is called price, I will assume that the letters there will be an error and it is better to write code like this

  if($(this).val()>=1){ $('.warning').css("display","none"); }else{ $('.warning').css("display","block"); } 
  • Unfortunately your code is not working - RavenTheX
  • 2
    @RavenTheX - I'm sorry, I need to replace $ this with $ (this). Corrected in the code - Nsk