{"id":952,"date":"2012-06-21T09:39:56","date_gmt":"2012-06-21T09:39:56","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=952"},"modified":"2012-06-21T09:39:56","modified_gmt":"2012-06-21T09:39:56","slug":"jquery-innerhtml-jquery-replace-innerhtml-of-div-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-innerhtml-jquery-replace-innerhtml-of-div-examples\/","title":{"rendered":"jQuery innerHTML Examples"},"content":{"rendered":"<p>If you have heard about\u00a0<strong>jQuery innerHTML<\/strong>, then at some point of time or other, you must have wondered how to use <em><strong>jQuery to replace innerHTML of Div<\/strong><\/em>. In this article, I am going to share some examples on how to do just that.<!--more--><\/p>\n<h2>Examples for using \u00a0jQuery to Replace innerHTML of Div<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=952\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Here is an example with complete source code that shows <em><strong>how to use jQuery to replace innerHTML of Div<\/strong><\/em>. The example assumes that there is a div with ID &#8220;my_div&#8221; with some default content and this content will need to be replaced with other text. Similarly, the content of the div with class &#8220;my_div2&#8221; gets replaced with replacement text.\u00a0\u00a0All this happens when a button is clicked.<\/p>\n<p><strong>Example: Here is the complete source code to replace innerHTML of div using jQuery<\/strong><\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Replace innerHTML of Div using jQuery&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n\n&lt;div id=\"my_div\"&gt;Default content&lt;\/div&gt;\n\n&lt;div class=\"my_div2\"&gt;Default content 2&lt;\/div&gt;\n\n&lt;input type=\"submit\" name=\"replace\" id=\"replace\" value=\"Replace\" \/&gt;\n\n&lt;script type=\"text\/javascript\" language=\"javascript\" &gt;\n\n$('#replace').click(function() {\n\n\t\/\/Using ID\n\t$(\"#my_div\").html(\"This is replacement text.\");\n\n\t\/\/Using Class\n\t$(\".my_div2\").html(\"This is replacement text 2.\");\n\n});\n\n&lt;\/script&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>When you run the above code, simply click on the button and you will see that the default text &#8220;Default content&#8221; is changed to &#8220;This is replacement text.&#8221;. Similarly, the\u00a0default text &#8220;Default content 2&#8221; is changed to &#8220;This is replacement text 2.&#8221;<\/p>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=952\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <em><strong>replace innerHTML of Div\u00a0using jQuery<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have heard about\u00a0jQuery innerHTML, then at some point of time or other, you must have wondered how to use jQuery to replace innerHTML of Div. In this article, I am going to share some examples on how to do just that.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[42,88,89,41],"class_list":["post-952","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-demos-2","tag-jquery-innerhtml","tag-jquery-replace-innerhtml","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-fm","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=952"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/952\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}