{"id":996,"date":"2017-10-28T12:54:59","date_gmt":"2017-10-28T12:54:59","guid":{"rendered":"http:\/\/blog.silverterra.net\/?p=996"},"modified":"2017-10-28T12:54:59","modified_gmt":"2017-10-28T12:54:59","slug":"identify-the-type-of-an-object","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=996","title":{"rendered":"identify the type of an object"},"content":{"rendered":"<blockquote><p>Goal: simple way to check the type of a page object<\/p><\/blockquote>\n<p>I have found many answers about this question but the useless is much more than the valuable. There is a simple way to identify objects on the page.<br \/>\nFor example I have a click listener and I want to know the type of the target object:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\n$(document).on({\r\n  click: function(event){\r\n    console.log(event.target, event.target.nodeName);\r\n  }\r\n});\r\n<\/pre>\n<p>No more like this. You can list all of the object types on your page with the following code piece<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nvar all = document.getElementsByTagName(&quot;*&quot;), a = [];\r\nfor (var item of all) {\r\n  var nn = item.nodeName;\r\n  !a[nn] &amp;&amp; (a[nn] = nn);\r\n}\r\nconsole.log(a);\r\nconsole.log(Object.keys(a).toString());\r\n-&gt; HTML,HEAD,META,TITLE,LINK,SCRIPT,BODY,STYLE,DIV,SPAN,IMG,UL,LI,BR,SELECT,OPTION,I,B,A,CANVAS\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Goal: simple way to check the type of a page object I have found many answers about this question but the useless is much more than the valuable. There is a simple way to identify objects on the page. For example I have a click listener and I want to know the type of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-996","post","type-post","status-publish","format-standard","hentry","category-javascript","category-web-trick"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=996"}],"version-history":[{"count":1,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/996\/revisions"}],"predecessor-version":[{"id":997,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/996\/revisions\/997"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}