{"id":4715,"date":"2019-05-23T13:12:03","date_gmt":"2019-05-23T07:42:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4715"},"modified":"2019-05-24T11:18:01","modified_gmt":"2019-05-24T05:48:01","slug":"document-object-model","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/document-object-model\/","title":{"rendered":"Document Object Model"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Document Object Model<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Date posted: 23\/05\/2019<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">DOM-Document Object Model<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"> Moreover, when html document is loaded in the browser, it becomes a document object. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> Likewise,&nbsp; How you are structure the web element is call the Document Object Model<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Subsequently,&nbsp; In the DOM, all HTML elements are defined as&nbsp;<strong>objects<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.mvps.net\/docs\/wp-content\/uploads\/2019\/03\/DOM.png\" alt=\"Image result for document object model\" width=\"339\" height=\"179\"\/><figcaption>DOM<br><br><\/figcaption><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html>\n&lt;head>\n  &lt;title>DOM&lt;\/title>\n&lt;\/head>\n\n  function myFunction()\n  {\n    console.log(document)\n  }\n\n&lt;body>\n  &lt;h1>Document Object Model&lt;\/h1>\n  &lt;button onclick=\"myFunction()\">Click me to print the DOM&lt;\/button>\n&lt;\/body>\n&lt;\/html>\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example,&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong> console.log(document)<\/strong>=&gt; print the whole document in browser.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Way to find HTML Elements:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Meanwhile,&nbsp;here is the way to find HTML elements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> document.getElementById(<em>id<\/em>)  =&gt;get the element by <strong>ID<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> document.getElementsByTagName(<em>name<\/em>)  =&gt;get the element by  <strong>TAGNAME<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> document.getElementsByClassName(<em>name<\/em>)   =&gt;get the element by  <strong>CLASSNAME<\/strong>  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, the sample code is<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">  GET ELEMENT BY Id <\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html>\n&lt;body>\n\n&lt;h2>  GET ELEMENT BY Id &lt;\/h2>\n\n&lt;button id=\"p1\" onclick=\"myFunction()\">click me&lt;\/button>\n\n\nfunction myFunction()\n{\n\tdocument.getElementById(\"p1\").innerHTML = \"New text!\";\n}\n\n\n\n&lt;p>The paragraph above was changed by a script.&lt;\/p>\n\n&lt;\/body>\n&lt;\/html>\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"488\" height=\"238\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getid.png\" alt=\"\" class=\"wp-image-4736\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getid.png 488w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getid-300x146.png 300w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"499\" height=\"249\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbyid1.png\" alt=\"\" class=\"wp-image-4737\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbyid1.png 499w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbyid1-300x150.png 300w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">GET ELEMENT BY TAG NAME<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html>\n&lt;body>\n\n&lt;h2>Finding HTML Elements by Tag Name&lt;\/h2>\n\n&lt;p>Hello World!&lt;\/p>\n&lt;button onclick=\"myFunction()\">click me&lt;\/button>\n\n&lt;p id=\"demo\">&lt;\/p>\n\n\nfunction myFunction()\n{\n\tvar x = document.getElementsByTagName(\"button\");\ndocument.getElementById(\"demo\").innerHTML = \n'onclick event by tag name ' + x.innerHTML;\n}\n\n\n&lt;\/body>\n&lt;\/html>\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"212\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbytag.png\" alt=\"\" class=\"wp-image-4738\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbytag.png 511w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbytag-300x124.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"552\" height=\"271\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbytag1.png\" alt=\"\" class=\"wp-image-4740\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbytag1.png 552w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/getbytag1-300x147.png 300w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for using&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/\">pheonix solutions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You find this tutorial helpful? Share with your friends to keep it alive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Document Object Model Date posted: 23\/05\/2019 DOM-Document Object Model Moreover, when html document is loaded in the browser, it becomes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[665],"class_list":["post-4715","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-dom","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1e3","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4715"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4715\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}