value forms in jQuery
To work with the value attribute of inputs, you can also use the val method, which allows you to read and write new values.
Let's look at an example. Let's say we have the following HTML code:
<input type="text" id="test" value="!!!">
Let's write the new value 'www' to the attribute value:
$('#test').val('www');
HTML the code will look like this:
<input type="text" id="test" value="www">
Now let's print the current value to the screen:
alert($('#test').val());
Also for the val method, it is possible to apply the function to each element in the set. The function takes the current number in the set as its first parameter, and its current value as its second.
There is one more nuance - for the tag textarea you cannot get the inner content via the method html. To do this, you need to use the method val.
Consider the following HTML code:
<textarea id="test">!!!</textarea>
in the Javascript code we write the method val:
alert($('#test').val()); // will bring out '!!!'
Most likely this was done to ensure uniformity of work with forms.
Set value of all inputs to '!'.
There are numbers in value of all inputs with class number. Make them become squares of these numbers.
Output value of input with class in.
Output sequentially value of each input.
Output the contents of textarea with class text.