DOM Basic Interview Questions
Mohan Mogi
·
2026-04-28
·
via DEV Community
<p>1.What is dom?<br> Dom stands for<br> D - Document<br> O - Object<br> M - Model<br> Dom is a programming interface for html documents.It represents the page as a tree of objects,so JavaScript can manipulate structure, style, and content dynamically.</p> <p>2.What is difference between dom and html?<br> DOM<br> Dom is a tree-like object model.Represents the current state for interaction.Dynamic; it updates in real-time.Manipulated by JavaScript to change the page.</p> <p>HTML<br> Html is a markup language.Defines the initial structure and content.Static; it doesn't change once sent.Written by developers, read by browsers.</p> <p>3.what is difference betweenand getelementbyid and queryselector?<br> getelementbyid:<br> Only ID strings (e.g., 'myID').Single element matching the ID.Faster directly accesses the element by ID.Faster; directly accesses the element by ID.</p> <p>queryselector<br> Any CSS selector (e.g., '#myID', '.myClass', 'div > p').The first element matching the selector.Slightly slower must parse CSS selectors.Available on document and any individual element.</p> <p>4.How to change the content of HTML elements</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmijinrg6itf6119jxjpw.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmijinrg6itf6119jxjpw.png" alt=" " width="589" height="193"></a></p> <p>output</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmu5fyxf98ygwtlgqfd0v.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmu5fyxf98ygwtlgqfd0v.png" alt=" " width="230" height="107"></a></p> <p>after click</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmxiwwd6rq0igzo6kurb.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmxiwwd6rq0igzo6kurb.png" alt=" " width="237" height="127"></a></p>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。