Assign value to span - jquery

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 value to span jquery

Example to assign text to span [jQuery]

<html xmlns="">
<head id="Head1" runat="server">
     <script type="text/javascript" src=""></script>
    <title>Assign value to span in jQuery</title>
    <script type="text/javascript">
      $(document).ready(function () {
        $("#submitbtn").click(function () {
          var inputValue = $("#inputText").val();
    <form id="form1" runat="server">
       <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">&nbsp;</span>

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.


Post a Comment