In this post we will see set a value to span tag using JQuer. To change value of span we can access span tag directly like $('span') and then using its .html() method we can assign some text to it.
![Assign text to span in jquery assign value to span jquery](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqejE6hrVRiWAUK3g2mUUy-PV-MZd1n7fg_YaXfRkcAue3eRK5XpR38aXFzNyQ61exJ1jNOvWr73IQc1R2hUvtsYZoqRvm25DT3csIZsrmrM3Nvb7CVCn0isdnPceKCDd2SN-x4CBB_ZDQ/s200/assign-text-to-span-jquery.png)
Example to assign text to span [jQuery]
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<title>Assign value to span in jQuery</title>
<script type="text/javascript">
$(document).ready(function () {
$("#submitbtn").click(function () {
var inputValue = $("#inputText").val();
$('span').html(inputValue);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>Type some text here to assign to span</label>
<input type="text" id="inputText"/>
<input type="button" id="submitbtn" value="Submit" /><br/>
<span style="width:500px;height:120px; background-color:thistle"> </span>
</div>
</form>
</body>
</html>
Summary:So to replace span tag text we get the object of span tag like $('span') and using .html() we can change value of span.