Please tell me, is there a js script that looks up the value table and displays them:

<script> $(document).ready( function() { $('#category').keyup(function(){ if($(this).val().length > 0){ $.ajax({ type: "POST", url:"/autocomplete/auto_cat.php?id=<?=$_GET['id']?>", dataType: 'json', data: {'choose' : $(this).val()}, success: function(res){ console.log(res); var content = ''; $.each(res, function(i, item){ content += "<div class='ott_g' data-id='"+res[i].id_c_p+"'>"+res[i].name_c_p+"</div>"; $("#pk").css({"margin-top": "29px", "background": "#fff", "position": "absolute", "margin-left": "138px", "width": "170px", "border": "2px dashed #e0e0e0", "text-align": "left", "padding": "5px", "font-size": "15px"}); }); $('.aut_cont').html(''); $('.aut_cont').append(content); } }); }else{ $('.aut_cont').html(''); } }); $('body').on( 'click', '.ott_g', function(){ var id = $(this).attr('data-id'); $('.user_id').val(id); var txt = $(this).text(); $('#category').val(txt); $('.aut_cont').html(''); }); } ); </script> 

The bottom line is when the content is displayed, we use the style:

 $("#pk").css({"margin-top": "29px", "background": "#fff", "position": "absolute", "margin-left": "138px", "width": "170px", "border": "2px dashed #e0e0e0", "text-align": "left", "padding": "5px", "font-size": "15px"}); 

How to remove this style after we chose a value? Now this is what happens: enter image description here

After selecting the value:

enter image description here

  • It is better to take out styles to the class, then add or remove the class. - Stepan Kasyanenko
  • @StepanKasyanenko Tell me how to add, remove classes? - Vladislav Samokhin
  • Using the addClass and removeClass . - Stepan Kasyanenko
  • @Stepan Kasyanenko can you help with the code? I'm new to js ... - Vladislav Samokhin

1 answer 1

Try to just pass an empty object to the css method.