jquery

Get and set HTML content using jQuery

//GET HTML INSIDE <body> TAG
$("body").html();

//SET HTML INSIDE <body> TAG
$("body").html('<div>Hello World</div>');

You can get and set HTML content inside the selector element using .html() method in jQuery. If you want to get the HTML that exists inside the selector you can just write .html() after your jQuery selector and it will return you the HTML content inside it. You can pass HTML content as a string inside .html() method if you want to set or change inside HTML content of the selector.

In the code snippet we are getting HTML content inside the body element using the first expression. Using the second expression we are setting HTML content inside body HTML element.

Was this helpful?