.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Code Snippets >> JQuery >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Set innerHTML using jQuery

Posted By:JQuery Developer       Posted Date: May 21, 2013    Points: 40    Category: JQuery    URL: http://www.dotnetspark.com  

This JQuery code sample will show you how to use innerHTML using JQuery. .html() is available in JQuery for the same purpose

innerHTML euuivalant in JQuery is .html()

using javascript innerHTML property of an element you can get or set its inner HTML content. This means when you have html string and you want to render in a web browser you can use innerHTML to set HTML content. remember if you want to only change the plain text you can use innerText property.

in JQuery we have .html() method which do the same thing as innerHTML. internally JQuery .html() calls innerHTML property of an element.

for changing the innerText property you can refer this code


JQuery Example

<script type="text/javascript">
    $(document).ready(function () {
        $("#myDivExample").html("<b> Hello World </b>"); // to make the font bold

html code for div tag

<div id="myDivExample">       

Click here for live demo

Full HTML and JQuery code of the above example

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>My Page Title</title> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#myDivExample").html("<b> Hello World </b>"); // to make the font bold }); </script> </head> <body> <div id="myDivExample"> </div> </body> </html>


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend