Tutorial :How to assign, clear and get value of a hidden field in jquery?



Question:

Consider a hiddenfield in the page HfId

<input type="hidden" id="HfId"/>  

How to assign,clear and get value of a hidden field in jquery? ANy suggestion...


Solution:1

The Element Selector of jQuery is exactly designed for this. It allows you to select all elements which fit the given name, id or class:

$("a")       // Get all a-elements  $("#id")     // Get all elements with the id "id"  $(".class")  // Get all elements with the class "class"  

The visibility or other properties of the element does not interfere with that, as it is still present in the DOM of the document.

Fields have the overloaded function val(), val($value) which allows you to get and set the value of the field:

$val = $("#HfId").val();  // Get  $("#HfId").val("");       // Clear  $("#HfId").val($newVal);  // Set  


Solution:2

$("#HfId").val("pony");  var x = $("#HfId").val();  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »