I have Id City on the page, which is basically a property of the model. I want to set it as null. I am trying to achieve this:
$("#City").val(null);
But this does not mean that the value is null.
You do not set the value of the elements to null , since HTML does not have the concept of null , undefined , etc., you remove the attribute or, even better, set it to an empty string:
null
undefined
$("#City").val("");
If you are trying to install / uninstall Id
$("#City").attr("id","");
or use removeAttr ()
If you are trying to set the value inside,
Using plain javascript, try using the setAttribute method,
setAttribute
document.getElementById("City").setAttribute("value" , "");
or without using the setAttribute method,
document.getElementById("City").value = "";
You can remove the identifier using jQuery prop() or attr() methods, for example:
jQuery
prop()
attr()
$('#City').prop('id', null);
or like this:
$('#City').attr('id', null);
Just in case:
jQuery Documentation for prop () method
jQuery Documentation for attr () Method
Source: https://habr.com/ru/post/954614/More articles:Linking an Image Using the HTML Helper - imageHow to use the generic functions pointer as a template parameter? - c ++Clear cookies for each test in the client configuration PhantomJS + GhostDriver + WebDriver - cookiesFind files with illegal Windows characters in a name on Linux - linuxBootstrap 3: place the sidebar on the left, but have it under the content when it crashes - cssAWS Authentication with Objective-C / Cocoa - objective-cHow to debug Gruntfile.js using log statements? - jqueryiOS7 Color transition of the status bar of the sidebar menu. Like iOS7 on Facebook - iosPython - finding duplicates in a dictionary list and grouping them - jsonPlayFramework 2.2 Java Action Composition - javaAll Articles