{"id":981,"date":"2012-06-15T09:50:39","date_gmt":"2012-06-15T07:50:39","guid":{"rendered":"http:\/\/hen.co.za\/blog\/?p=981"},"modified":"2012-06-15T09:50:39","modified_gmt":"2012-06-15T07:50:39","slug":"javascript-tip-innertext-or-textcontent","status":"publish","type":"post","link":"https:\/\/hen.co.za\/blog\/2012\/06\/javascript-tip-innertext-or-textcontent\/","title":{"rendered":"Javascript tip: innerText or textContent"},"content":{"rendered":"<p>Just a quick tip how to handle using an UI object&#8217;s innerText property properly. Even today there are differences on how web browsers give you access to the &#8216;Text&#8217; content of an HTML element. Let say you have the following html:<\/p>\n<p>&lt;p\u00a0id=&#8221;mine&#8221;&gt;This is some text&lt;\/p&gt;<\/p>\n<p>To get the &#8216;content you must use the following:<\/p>\n<p>IE and Chrome<\/p>\n<blockquote><p>mine.innerText<\/p><\/blockquote>\n<p>but in Firefox<\/p>\n<blockquote><p>mine.textContent<\/p><\/blockquote>\n<p>To make a &#8216;universal function to get this text you can use the following function:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction getInnerText(obj){\r\n  if (obj){\r\n    if (obj.innerText)\r\n      return obj.innerText;\r\n    else\r\n      return obj.textContent\r\n    }\r\n  else\r\n    return &quot;&quot;;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just a quick tip how to handle using an UI object&#8217;s innerText property properly. Even today there are differences on how web browsers give you access to the &#8216;Text&#8217; content of an HTML element. Let say you have the following &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/hen.co.za\/blog\/2012\/06\/javascript-tip-innertext-or-textcontent\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,16],"tags":[91,202,201,203,204],"class_list":["post-981","post","type-post","status-publish","format-standard","hentry","category-development","category-reference","tag-browser","tag-innertext","tag-javascript","tag-textcontent","tag-web-browser"],"_links":{"self":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/comments?post=981"}],"version-history":[{"count":2,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/981\/revisions"}],"predecessor-version":[{"id":983,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/981\/revisions\/983"}],"wp:attachment":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/media?parent=981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/categories?post=981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/tags?post=981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}