{"id":18710,"date":"2020-10-26T13:20:45","date_gmt":"2020-10-26T20:20:45","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=18710"},"modified":"2023-12-01T04:03:25","modified_gmt":"2023-12-01T12:03:25","slug":"javascript-innertext-innerhtml","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/","title":{"rendered":"JavaScript innerHTML and innerText: A Guide"},"content":{"rendered":"\n<p>You\u2019ll need to know how to change the text or the HTML that appears on the page to make your sites more interactive. That\u2019s where the <em>innerText<\/em> and <em>innerHTML<\/em> HTML attributes come in.<\/p>\n\n\n\n<p>These attributes make it easy to change a DOM element\u2019s text and its HTML code. In this guide, you\u2019ll learn how to use the JavaScript <em>innerText<\/em> and <em>innerHTML<\/em> attributes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is JavaScript innerHTML?<\/h2>\n\n\n\n<p>The JavaScript innerHTML property sets the HTML contents of an element on a web page. InnerHTML is a property of the HTML DOM. innerHTML is often used to set and modify the contents of a &lt;p&gt; element.<\/p>\n\n\n\n<p>You can use innerHTML like so:<\/p>\n\n\n\n<p>document.getElementById(&#8220;paragraph&#8221;).innerHTML = &#8220;Career Karma!&#8221;;<\/p>\n\n\n\n<p>This line of code sets the contents of the &#8220;paragraph&#8221; &lt;p&gt; element to &#8220;Career Karma!&#8221; The <a href=\"https:\/\/careerkarma.com\/blog\/javascript-getelementbyidv\/\">getElementById() method<\/a> retrieves an element by its ID.<\/p>\n\n\n\n<p>The browser defines a <a href=\"https:\/\/careerkarma.com\/blog\/what-is-the-javascript-dom\/\"><\/a><a href=\"https:\/\/careerkarma.com\/blog\/what-is-the-javascript-dom\/\">Document Object Model (DOM)<\/a> when a page loads. This DOM is a series of objects displayed on the page.<\/p>\n\n\n\n<p>The DOM means you don\u2019t have to change the HTML code every time you want to change a web element. You can use the DOM and JavaScript to change how the page appears in a particular session.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is JavaScript innerText?<\/h2>\n\n\n\n<p>The JavaScript innerText property sets the text content of an element. It also sets the contents of its descendants. Descendants may include &lt;span&gt; tags inside a paragraph.<\/p>\n\n\n\n<p>The syntax of innerText is similar to that of innerHTML:<\/p>\n\n\n\n<p>document.getElementById(&#8220;element&#8221;).innerText = &#8220;This is a test.&#8221;;<\/p>\n\n\n\n<p>This sets the text value of the element with the id &#8220;element&#8221; to &#8220;This is a test.&#8221;<\/p>\n\n\n\n<p>You can test these methods by going into your JavaScript console and selecting an element to change:<\/p>\n\n\n\n<p>This changes the contents of the first &lt;p&gt; HTML tag on a web page. If you want to replace text, you can use the <em>innerText<\/em> attribute:<\/p>\n\n\n\n<p>This changes the contents of the second paragraph (denoted by the number 1) on the page to \u201cThis is a test\u201d.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using innerHTML and innerText in JavaScript<\/h2>\n\n\n\n<p>Let\u2019s get started by changing text on a web page. We\u2019re going to create a simple flashcard web page. This web page will display a question about HTML. It will have a button which, when clicked, will reveal the answer to a question about HTML.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create a Web Page<\/h3>\n\n\n\n<p>Our first step is to create an index.html file for our front-end:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n   \t &lt;title&gt;HTML Flashcard App&lt;\/title&gt;\n\t&lt;link rel=&quot;stylesheet&quot; href=&quot;.\/styles.css&quot; \/&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n   \t &lt;div class=&quot;flashcard&quot;&gt;\n   \t\t &lt;h2&gt;Does a hyperlink only apply to text?&lt;\/h2&gt;\n   \t\t &lt;p&gt;The answer will be revealed when you press &quot;Show answer&quot;&lt;\/p&gt;\n   \t\t &lt;button id=&quot;showAnswer&quot;&gt;Show answer&lt;\/button&gt;\n\t\t &lt;br \/&gt; &lt;br \/&gt;\n\t\t &lt;div id=&quot;showMessage&quot;&gt;&lt;\/div&gt;\n   \t &lt;\/div&gt;\n\t&lt;script src=&quot;.\/scripts.js&quot;&gt;&lt;\/script&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<p>This page creates a container with three components. First, we have the question we are asking the user. We have the message about how to reveal the answer. Our page finishes with a button to reveal the answer.<\/p>\n\n\n\n<p>Our code returns the text content of our elements:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/6T3AqzAPinI7lFyjQvH2K5A7rt-1RCErWqdxCPfZsgbtsRnymdUu9CRkmnu6SLrXKDZ19i9pObkHLyFwA3q3CI2vsm1IfCvU3AYYkweMNHLbOYGhgByfgvd417wxRACkh08KQrYx\" alt=\"\"\/><\/figure>\n\n\n\n<p>We are going to apply some CSS styles in a styles.css file to make our page prettier:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;style&gt;\n.flashcard {\n    margin: auto;\n    width: 50%;\n    padding: 50px;\n    margin-top: 10%;\n    background-color: lightgreen;\n    text-align: center;\n}\n\nbutton {\n    border: none;\n    background-color: hotpink;\n    padding: 10px;\n    border-radius: 10px;\n}\n&lt;\/style&gt;<\/pre><\/div>\n\n\n\n<p>Now let&#8217;s take a look at our web page:<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Acuv0IVyLlR1c2-eiCi4KGUjIRL47I85nFJfPbVzO_dFk7bGtEq0PvcutixgrZEGOCBva3hJkyy7XP83DahvKKYgPdIp0jfHD2sY3hdOSUjBjVcAhxeIgOwOH733NW6syaFhNluO\" alt=\"\"\/><\/figure>\n\n\n\n<p>Our site shows something that looks more like a flash card. We\u2019ve styled our button.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Change Text Using JavaScript innerHTML and innerText<\/h3>\n\n\n\n<p>We want the answer to the question to be revealed when the button is clicked. First, we\u2019re going to select the text and button elements which we are going to use in our JavaScript code. We\u2019ll be writing all this code in our scripts.js file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var answerText = document.querySelector('p');\nvar button = document.querySelector('button');<\/pre><\/div>\n\n\n\n<p>Next, we\u2019re going to create a <a href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/\">JavaScript function<\/a>. This function reveals the answer to our question when the button is clicked:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function showAnswer() {\n\tanswerText.innerText = &quot;No. Hyperlinks can be used on both text and images.&quot;;\n}<\/pre><\/div>\n\n\n\n<p>To activate our function on a button press, we are going to create a simple event listener. This listener listens for a click on our button:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>button.addEventListener('click', showAnswer);<\/pre><\/div>\n\n\n\n<p>We\u2019ve finished setting up our flash card app. If we view our web page and click on the \u201cShow answer\u201d button, the text in our paragraph is changed to reveal the answer:\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/G32PBB7NlaNkaBMqrMbiXIRTk4WfRCiDZn-p0ASqwJR2YnF3v2TfKCYDYLAbaM_YITmwE0s52v4UF2pjRB2KsNY4AgffYHEvolTDRmtmI3uJSQYxwFf39Hdqac7lXxajCJ_kT8nA\" alt=\"\"\/><\/figure>\n\n\n\n<p>We could add more functionality to this app using JavaScript <em>innerHTML<\/em>. Suppose we want a message to be displayed at the bottom of the flash card once the button is clicked. This message should appear in red. We could create this message using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var message = document.querySelector('#showMessage');\n\nfunction showAnswer() {\n\tanswerText.innerText = &quot;No. Hyperlinks can be used on both text and images.&quot;;\n\tmessage.innerHTML = &quot;&lt;span style='color:red;'&gt;You have revealed the answer.&lt;\/span&gt;&quot;;\n}<\/pre><\/div>\n\n\n\n<p>Let\u2019s try to run our code with the revised <em>showAnswer()<\/em> function and the new query selector we wrote:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Dh0CjeyiLuY70ytmmm3uAtYgvmyL7OZ3sHKBNDscuEavoAMqc_8MuU78UkJPaM2vNCY5tnOpcpfDDO3_4TH5eMbd2oqBpSNADvr06KOO30yhHUSvCH0WbWHr94yBEYuWknfTJG6g\" alt=\"\"\/><\/figure>\n\n\n\n<p>We\u2019ve used the <em>innerHTML<\/em> method to add a <a href=\"https:\/\/careerkarma.com\/blog\/html-span\/\">HTML &lt;span&gt;<\/a> tag to our site. This tag displays a message that appears in red when a user presses the show answer button.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JavaScript innerText vs. innerHTML<\/h2>\n\n\n\n<p>Both the innerText and innerHTML properties let you access and change the contents of a tag. innerText returns  the text without any descendants or spacing. innerHTML returns the text including any descendants and spacing.<\/p>\n\n\n\n<p>You would use innerText if you want to see the contents of an element in plain text. Using innerHTML is more appropriate if you want to see all the HTML tags that appear in a string.<\/p>\n\n\n\n<p>In sum, innerText lets you work with plain text whereas innerHTML lets you work with the HTML in a string.<\/p>\n\n\n\n<p>Both innerText and innerHTML have wide support in modern browsers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The <em>innerText<\/em> and <em>innerHTML<\/em> properties manipulate the HTML DOM. innerText retuns the text content of an element without spacing or descendants. innerHTML returns the content of an element and any spacing and descendants.<\/p>\n\n\n\n<p>As a bonus challenge, see whether you can make our code above hide an answer when the button is clicked a second time. Your code should:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Hide the answer when a user clicks the button<\/li><li>Change the text of the button from \u201cShow answer\u201d to \u201cHide answer\u201d when the answer is showing.<\/li><li>Keep the \u201cYou have revealed the answer\u201d message after a user has pressed \u201cHide answer\u201d.<\/li><\/ul>\n\n\n\n<p>If you&#8217;re looking for more tutorials that will help you learn JavaScript, check out our <a href=\"https:\/\/careerkarma.com\/blog\/tutorial-for-javascript-beginners\/\">best tutorials for JavaScript beginners guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"You\u2019ll need to know how to change the text or the HTML that appears on the page to make your sites more interactive. That\u2019s where the innerText and innerHTML HTML attributes come in. These attributes make it easy to change a DOM element\u2019s text and its HTML code. In this guide, you\u2019ll learn how to&hellip;","protected":false},"author":240,"featured_media":18058,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-18710","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript innerHTML and innerText: A Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"innerText and innerHTML allow you to manipulate the Document Object Model on a web page. On Career Karma, learn how to use these JavaScript attributes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript innerHTML and innerText: A Guide\" \/>\n<meta property=\"og:description\" content=\"innerText and innerHTML allow you to manipulate the Document Object Model on a web page. On Career Karma, learn how to use these JavaScript attributes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-26T20:20:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:03:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"JavaScript innerHTML and innerText: A Guide\",\"datePublished\":\"2020-10-26T20:20:45+00:00\",\"dateModified\":\"2023-12-01T12:03:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/\"},\"wordCount\":970,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/\",\"name\":\"JavaScript innerHTML and innerText: A Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg\",\"datePublished\":\"2020-10-26T20:20:45+00:00\",\"dateModified\":\"2023-12-01T12:03:25+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"innerText and innerHTML allow you to manipulate the Document Object Model on a web page. On Career Karma, learn how to use these JavaScript attributes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-innertext-innerhtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript innerHTML and innerText: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript innerHTML and innerText: A Guide | Career Karma","description":"innerText and innerHTML allow you to manipulate the Document Object Model on a web page. On Career Karma, learn how to use these JavaScript attributes.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript innerHTML and innerText: A Guide","og_description":"innerText and innerHTML allow you to manipulate the Document Object Model on a web page. On Career Karma, learn how to use these JavaScript attributes.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-10-26T20:20:45+00:00","article_modified_time":"2023-12-01T12:03:25+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"JavaScript innerHTML and innerText: A Guide","datePublished":"2020-10-26T20:20:45+00:00","dateModified":"2023-12-01T12:03:25+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/"},"wordCount":970,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/","url":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/","name":"JavaScript innerHTML and innerText: A Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg","datePublished":"2020-10-26T20:20:45+00:00","dateModified":"2023-12-01T12:03:25+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"innerText and innerHTML allow you to manipulate the Document Object Model on a web page. On Career Karma, learn how to use these JavaScript attributes.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/charles-deluvio-pjAH2Ax4uWk-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-innertext-innerhtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript innerHTML and innerText: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=18710"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18710\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18058"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=18710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=18710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=18710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}