Uncaught TypeError: $(..id is not a function - Cannot change the ID of an element

Uncaught TypeError: $(..id is not a function - Cannot change the ID of an element

I am trying to change the id of a div at runtime, but getting the error . Its a aspnet core program, so the @1 value is a dynamic value that translates to an integer value e.g. 1

  1. Uncaught TypeError: $(...).parent(...).closest(...).id is not a function    

My code is

  1.     $("#hi").attr('id', @i);

in my added scripts I have

 
  1. <script src=" https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha384-xBuQakNTNrHIW2I5f" crossorigin="anonymous"></script>
        
        
        
                <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>