The following web example consists of a div with id content and an input with id log. The scripts executed, using the val() function, will be the following:
- Store in the variable my_value the value of the input text with id log.
- Select the div with id content and I set as html content the value of the variable my_value.
- Select the input text with id log and I add the value "Insert Value".
xxxxxxxxxx
<div id="content"></div>
<input type="text" name="log" value="Your Login" id="log">
<!--Script jQuery-->
<script>
//Store in the variable my_value the value of the input text with id log
var my_value = $("input[type=text]#log").val();
//Select the div with id content and I set as html content the value of the variable my_value
$('#content').html(my_value);
//Select the input text with id log and I add the value "Insert Value".
$("input[type=text]#log").val("Insert Value");
</script>
<!--JQuery Library-->
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
Interesting Articles