{"id":567,"date":"2022-11-05T12:16:38","date_gmt":"2022-11-05T12:16:38","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=567"},"modified":"2022-11-05T12:16:38","modified_gmt":"2022-11-05T12:16:38","slug":"what-are-element-access-methods-in-javascript","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/","title":{"rendered":"What Are Element Access Methods In Javascript?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">In javascript,  we have so many methods for accessing elements but, There are five important or common methods-<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>document.getElementByid<\/li><li>document.getElementByTageName<\/li><li>document.getElementByClassName<\/li><li>document.queryselector<\/li><li>document.queryselectorall<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. Document.getElementByid<\/h2>\n\n\n\n<p>The&nbsp;document&nbsp;method&nbsp;getElementByid()&nbsp;returns an&nbsp;element&nbsp;object representing the element whose&nbsp;id&nbsp;property matches the specified string. &nbsp;Since element IDs are required to be unique if specified, they&#8217;re a useful way to get access to a specific element quickly.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Syntax= getElementById(id)<\/strong><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2.Document.getElementByTageName<\/h2>\n\n\n\n<p>The&nbsp;getElementsByTagenamemethod of&nbsp;document&nbsp;interface returns an&nbsp;htmlcollection&nbsp;of elements with the given tag name. The complete document is searched, including the root node. returned&nbsp;<code>htmlcollection<\/code>&nbsp;is live, meaning that it updates itself automatically to stay in sync with the DOM tree without having to call&nbsp;<code>document.getElementsByTagName()<\/code>&nbsp;again.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Syntax= getElementsByTagName(name)<\/strong>\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3.document.getElementByClassName<\/h2>\n\n\n\n<p>The&nbsp;getElementByClassName()&nbsp;method of&nbsp; document interface returns an array-like object of all child elements which have all of the given class name(s). <\/p>\n\n\n\n<p>When called on the&nbsp;document object, the complete document is searched, including the root node. You may also call&nbsp;&nbsp;The&nbsp;getElementByClassName() on any element; it will return only elements which are descendants of the specified root element with the given class name(s).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Synta= getElementsByClassName(names)<\/strong>\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. document.queryselector<\/h2>\n\n\n\n<p>.The document&nbsp;method&nbsp;queryselector(0 returns the first&nbsp;element within the document that matches the specified selector, or group of selectors. If no matches are found,&nbsp;<code>null<\/code>&nbsp;is returned. The matching is done using depth-first pre-order traversal of the document&#8217;s nodes starting with the first element in the document&#8217;s markup and iterating through sequential nodes by order of the number of child nodes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Syntax= querySelector(selectors)<\/strong><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax\">5. document.queryselectorall<\/h2>\n\n\n\n<p>The&nbsp;document method&nbsp;queryselectorall()&nbsp;returns a static (not live)&nbsp;&nbsp;representing a list of the document&#8217;s elements that match the specified group of selectors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Syntax= querySelectorAll(selectors)<\/strong><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In javascript, we have so many methods for accessing elements but, There are five important or common methods- document.getElementByid document.getElementByTageName document.getElementByClassName document.queryselector document.queryselectorall 1. Document.getElementByid The&nbsp;document&nbsp;method&nbsp;getElementByid()&nbsp;returns an&nbsp;element&nbsp;object&#8230; <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-567","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What Are Element Access Methods In Javascript? - DevOps | SRE | DevSecOps<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Are Element Access Methods In Javascript? - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"In javascript, we have so many methods for accessing elements but, There are five important or common methods- document.getElementByid document.getElementByTageName document.getElementByClassName document.queryselector document.queryselectorall 1. Document.getElementByid The&nbsp;document&nbsp;method&nbsp;getElementByid()&nbsp;returns an&nbsp;element&nbsp;object...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-05T12:16:38+00:00\" \/>\n<meta name=\"author\" content=\"shivam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shivam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/\"},\"author\":{\"name\":\"shivam\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\"},\"headline\":\"What Are Element Access Methods In Javascript?\",\"datePublished\":\"2022-11-05T12:16:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/\"},\"wordCount\":321,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/\",\"name\":\"What Are Element Access Methods In Javascript? - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"datePublished\":\"2022-11-05T12:16:38+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-are-element-access-methods-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What Are Element Access Methods In Javascript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\",\"name\":\"DevOps | SRE | DevSecOps\",\"description\":\"Automation means Cost, Quality, Time\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\",\"name\":\"shivam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"caption\":\"shivam\"},\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/author\\\/shivam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What Are Element Access Methods In Javascript? - DevOps | SRE | DevSecOps","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:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"What Are Element Access Methods In Javascript? - DevOps | SRE | DevSecOps","og_description":"In javascript, we have so many methods for accessing elements but, There are five important or common methods- document.getElementByid document.getElementByTageName document.getElementByClassName document.queryselector document.queryselectorall 1. Document.getElementByid The&nbsp;document&nbsp;method&nbsp;getElementByid()&nbsp;returns an&nbsp;element&nbsp;object...","og_url":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-11-05T12:16:38+00:00","author":"shivam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"shivam","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/"},"author":{"name":"shivam","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"headline":"What Are Element Access Methods In Javascript?","datePublished":"2022-11-05T12:16:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/"},"wordCount":321,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/","url":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/","name":"What Are Element Access Methods In Javascript? - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"datePublished":"2022-11-05T12:16:38+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/what-are-element-access-methods-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopstrainer.in\/blog\/"},{"@type":"ListItem","position":2,"name":"What Are Element Access Methods In Javascript?"}]},{"@type":"WebSite","@id":"https:\/\/www.devopstrainer.in\/blog\/#website","url":"https:\/\/www.devopstrainer.in\/blog\/","name":"DevOps | SRE | DevSecOps","description":"Automation means Cost, Quality, Time","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopstrainer.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53","name":"shivam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","caption":"shivam"},"url":"https:\/\/www.devopstrainer.in\/blog\/author\/shivam\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/comments?post=567"}],"version-history":[{"count":1,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/567\/revisions"}],"predecessor-version":[{"id":568,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/567\/revisions\/568"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}