jQuery .html() method

The jQuery html() method is used set or get the content (texts with HTML codes) of selected elements. You can use this method when you want to add HTML code along with the content or a text value to elements.

Syntax of .html() Method

To return content:


To set content:


➡️ text() method


Let us assume, I have a label control and I want to change the text along with the markup of the label dynamically. Here's what I'll do.

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

  <input type="text" id="emp" value="" />
  <p><input type="button" id="bt" value="Change Label Text" /></p>
  <label id="lblEmp">N/A</label>

 $(document).ready(function () {
    $('#bt').click(function () {
      let empName = $('#emp').val();
      $('#lblEmp').html('Hello <span style="text-transform:capitalize;">' + empName + '</span>');
Try it

➡️ jQuery Methods