We can easily access the inner HTML tags contents and we can also set the inner HTML content of HTML tags using the jQuery html() function.
$("TagSelector").html();
For setting or assigning the content to HTML tag or element.
$("TagSelector").html("Content Value");
We are considering two examples , example to get the HTML element content and example to assign or set the content to the HTML tag.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button> Get div content</button>
<div id="mydiv1">Welcome to jQuery html() method tutorial. I am in Div with id equal to mydiv1</div>
<script type="text/javascript">
$("button").click(function()
{
var divContent= $("#mydiv1").html();
alert(divContent);
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button> Set div content</button>
<div id="mydiv2"></div>
<script type="text/javascript">
$("button").click(function()
{
$("#mydiv2").html("Welcome to CodingPk. I am the content assigned to div id equal to mydiv2");
});
</script>