Most voted "dom" questions
DOM (Document Object Model - Document Object Model) is a W3C specification for a platform and language independent interface, where one can dynamically change and edit the structure, content and style of an electronic document, allowing the document to be later processed and the results of that processing, incorporated back into the document itself.
Learn more…268 questions
Sort by count of
-
57
votes2
answers3691
viewsWhat is DOM, Render Tree and Node?
I’m a beginner in JS and try to understand the theory, but all the articles I find on DOM are too "scientific". There wouldn’t be a simpler way to explain this to a "layman"?
-
57
votes3
answers1826
viewsWhy use getElementById if id is in the window?
Recently in my study I noticed an object that manipulated the DOM of the element that had the same name in its id. teste.style.border = '1px solid #CCC'; teste.style.width = '500px';…
-
54
votes2
answers126902
viewsWhat is the difference between $(Document). ready() and window.onload?
There is a difference between $(document).ready() e window.onload apart from one being Javascript and the other being jQuery? I see both events are triggered as soon as the GIFT (Document Object…
-
33
votes3
answers21328
viewsCreate HTML element with Javascript (appendchild vs innerHTML)
Recently I’m creating a lot of HTML dynamically. Example var table = document.createElement('table'); table.style = 'width:500px;border:1px solid #CCC;'; var tbody = document.createElement('tbody');…
-
32
votes1
answer3647
viewsWhat is shadow DOM?
When I was reading about some Javascript frameworks, for example the React, I read the expression a few times shadow gift in some articles. It even seems that it is possible, in Chrome console…
-
19
votes3
answers1712
viewsWhy is it considered wrong/bad to repeat an HTML ID?
I think the title says it all, why is it considered wrong to repeat HTML Ids? I notice a lot of people doing things like: <div id="foo">bar</div> <div id="foo">baz</div> To…
-
17
votes4
answers1235
viewsDoes the order of CSS styles influence the render tree?
During the Paint from the document by the browser the order of the properties of the CSS classes may interfere in how we perceive the page’s "assembly"? Especially in slower connections, we…
-
16
votes3
answers16866
viewsHow to check Undefined correctly in Javascript
What is the best way to check whether an element/variable is undefined in Javascript? I’ve seen some examples using variavel === undefined and others using typeof variavel == "undefined".…
-
15
votes1
answer222
viewsCan displaying many elements in the DOM impair performance?
I really like using libraries like Vue and AngularJs and my favorite implementation was to Infinite Scroll (or loading on demand). I mean, I initially upload 15 records via ajax. If the user scrolls…
-
14
votes2
answers8665
viewsHow to clone an element in Javascript?
Is it possible to obtain an exact clone of a given HTML element? so that the clone contains all properties exactly the same? If there is, I would like to know how to proceed to perform this clone,…
-
14
votes2
answers355
viewsWhat are the main differences and advantages of using Shadow DOM and Virtual DOM?
Analyzing carefully for a better performance of an application, what are the main benefits in using one or the other and their differences? Angular for example works with the Shadow DOM approach,…
-
13
votes1
answer10939
viewsWhat is parse, and how the parse of DOM works in HTML5
I started to study more CSS3 in depth, and I ended up wanting to better understand how the HTML rendering works in the Document Object Model (DOM), and how this HTML and CSS (and JS) markup is made…
-
12
votes1
answer193
viewsWhen is it useful to capture DOM events?
The events of the DOM traverse the document tree up to his target, with a phase of catching and a phase of bubbling. The default behavior when creating a Listener with addEventListener is to treat…
-
12
votes2
answers319
viewsDocument.getElementById('ID'). func(....) vs ID.func(...)
Yesterday I came across a curious thing, I had no idea you could do it this way. Until now I did it this way: document.getElementById('a').innerHTML = 'CONTENT'; <div id="a"></div> But…
-
11
votes3
answers318
viewsIs referring to an element via its id considered bad?
In Javascript, you can refer to any element that has a id (and in some cases a name) using simply an identifier with the same name - without the need to declare it: <div…
-
11
votes2
answers262
viewsHow to parse syntactically malformed HTML?
As part of a procedure, I need to extract the contents of a table present on a page. I’m using Curl to get the raw HTML data and the Simple HTML DOM Parser to parse and process HTML. <?php //…
-
9
votes1
answer84
views$ and $$ are now native browser functions?
When using the console on a Javascript-free page I noticed that when typing $ had the same effect as document.querySelector and while typing $$ had the same effect as document.querySelectorAll.…
-
9
votes1
answer328
viewsWhat is the difference between using appendchild and insertAdjacentHTML?
In a code from which I will have to add an element within a DIV. What’s the difference between first creating the element and adding it to div through the appendchild and doing…
-
8
votes3
answers997
viewsHow do I add jQuery library with Javascript?
I would like to know how to load the jQuery library with pure Javascript and run something simple with jQuery after its load? My code is like this: function colocaScript(){ var scriptJquery =…
-
8
votes4
answers1082
viewsHow to verify that the properties of the window object are native?
I’m using Shim that modifies several of the properties in the window object of browsers. At this point I need to validate whether one of the specified properties is native or a Shim. Because Shim…
-
8
votes1
answer438
viewsReturn value processed in Javascript to the Managed bean
Is it possible to return processed value in Javascript to the Managed bean? What’s different in this process is that I run the JS method on the bean, like this:…
-
8
votes2
answers174
viewsGrouped id rendering speed vs class
Some time ago I saw some CSS rendering tests using id be faster than rendering using class, due to the amount of id be often lower in the document than the number of classes (one of the tests you…
-
7
votes5
answers1446
viewsIs it possible to include elements in the DOM after it is loaded and ready?
I have a table that, depending on the amount of an X value, inserts a set of attributes at the bottom of the page (fields). These elements have events assigned to them. But that’s not the point.…
-
7
votes1
answer1723
viewsHow to use the Mutationobserver() of the correct vein?
I know that the MutationObserver() was developed to detect HTML DOM changes. But I’d like to know how it works in practice. We create a hypothetical situation, how about? There is a <div> with…
-
7
votes3
answers274
viewsHow to manipulate the DOM of a page before it finishes loading?
I am making a Lazy Loader in pure javascript, currently I put my embed script at the end of the HTML that identifies the images and, if they are not ready (for example loaded from the cache), this…
-
6
votes1
answer50551
viewsCapturing an element’s id with javascript click
In the Document there are three <div>, all with the event onclick calling a function. By clicking on any of the three, I would like to capture the id of the <div> clicked. How can I…
-
6
votes2
answers282
viewsConflict between Simple_html_dom and Nonobject-Oriented functions
I’m developing an app that has to access a list of websites stored in a database, upload all their links. It’s a test application but I’ve found a difficulty. The routine is this one: function…
-
6
votes1
answer181
viewsIs "new Domparser" safer than "Document.createelement"?
I created a script to try to remove unsafe content when injecting DOM (I’m using it in extensions/Addons for browsers): var str = "<strong>Hello</strong> mundo <script…
-
6
votes3
answers641
viewsWhat is Unobtrusive Javascript?
What is Unobtrusive Javascript and what its differential when writing Javascript functions in the HTML document?
-
5
votes3
answers1058
viewsCreateelement() method in PHP
In javascript, I can do: var span = document.createElement('span'); span.innerHTML = 'foo'; span.className = 'bar'; Is there something similar for you to create a ElementNode in PHP, at least with…
-
5
votes2
answers1901
viewsEvent click Jquery in selector . class
I created several div by using jQuery to assign them the CSS class numero: for(...) textoHTML += "<div class='numero par'>"+sorteado+"</div> <!-- numero par-->\n"; ... textoHTML +=…
-
5
votes1
answer90
viewsAdd properties to the [Node] element
Is there a problem with adding custom properties directly to the [Node] element? For example: document.getElementById('minhaDiv').minhaPropriedade = 'teste'; I’m using Firefox and I haven’t had…
-
5
votes1
answer435
viewsAccess through Javascript/Jquery an element that came through AJAX after DOM LOAD
I am developing a WEB APP with Angularjs, there is an element that is coming to the DOM after its loading (load), I am trying to write an event : $('elemento').click() But when finished rendering…
-
5
votes5
answers269
viewsChanging text in several different places of the HTML page
I’m thinking of developing a i18n for an application. My idea is: there is a text #i18n_label_name at a certain place on the page and #i18n_label_contact elsewhere. Question: What is the most…
-
5
votes3
answers10282
viewsHow to navigate a children and a div with Javascript?
I need a function that goes through #paicasas and leaves the background of all children "casa1,casa2...". I tried to do it but I know it’s far from right. function apagar(){ for(var i in…
-
5
votes1
answer458
viewsWhat is the difference between innerHTML and appendchild in JS?
What’s the difference between innerHTML and the appendChild? In my opinion they are very similar.
-
4
votes3
answers4195
viewsHow to insert an element between two elements?
Explanation: I have a <div> parent containing two <div> daughters, however I would like to insert a <table> using javascript, between, that is, in the middle of these two…
-
4
votes2
answers3494
viewsHow to change the text of the OK button of Alert?
People I need an Alert with the "Confirm" button instead of the "OK" button. how do I do that?
-
4
votes1
answer291
viewsWhat’s the difference between Nodelist and Htmlcollection?
I was reading a code when I came across the following question, I was wondering if anyone could enlighten me?
-
4
votes3
answers627
viewsHow to collect the height of an element with jQuery
Oops, I’m not getting the height of an object in the document. I have a slider, which works with ul > li (may be relevant), and inside a slide <li>, I am placing via javascript and c# three…
-
4
votes1
answer1827
viewsHow to replace the HTML content of a div using php Domelement
I’m trying this way libxml_use_internal_errors(true); //pegar o conteudo de um pagina web $doc = new DomDocument(); $doc->loadHTMLFile('http://www.astralsaudeambiental.com.br/'); $div =…
-
4
votes1
answer58
viewsIs the window rendered by the gift or does it come before that?
A curiosity: I wonder if the window is rendered by dom when loading the window, as the document is usually window.document.html. Or the dom comes after this parameter?…
-
4
votes1
answer299
viewsHelp with PHP repeat structure - PARSER - simple_html_dom.php
I’m doing a parser with simple_html_dom.php where I pull all the links from a given page. I can pull the links and assign to an array, here comes the problem: this page has a maximum display limit…
-
4
votes4
answers356
viewsTwo-dimensional Array
I would like to go through a two-dimensional array according to the code: var cadeiras = [[true, false, true, true, true, false, false, true, true, true, false, false], [true, false, true, true,…
-
4
votes1
answer164
viewsWhat is each of the "data types" of the DOM?
I’m studying about the GIFT and I came up with a question regarding his data types, which are: document element nodeList node attribute namedNodeMap I didn’t really understand what each type of data…
-
4
votes1
answer166
viewsWhen trying to create an object using `this` the console says that the property is Undefined
I’m learning to use objects in Javascript, and I stumbled upon an unforeseen behavior in my object. In the case when I try to store an element via DOM within a property the console says that the…
-
4
votes5
answers3663
viewsHow to scan an array and insert the elements into HTML with JS
I am studying the DOM of JS and had some difficulties. I need to show the elements of this vector as li tags of HTML: let nomes = ["Diego", "Gabriel", "Lucas"]; My code is this: function gerar(){…
-
4
votes1
answer71
viewsplace the result of each iteration of the cycle in html for
If you could help me with a question, I would really appreciate it! So, I’m very junior in javascript and I’m doing an exercise, where I wanted to put the results of my cycle out to appear in HTML,…
-
3
votes2
answers1168
viewsPositioning scripts and css links in an html document
I always put the CSS scripts and links at the top of the document in the head of the document. Now I realize that there is another concept where the calls to scripts and CSS, are at the bottom of…
-
3
votes1
answer356
viewsdiv.childNodes.item(0) recognizes tab or space as child
I use Ubuntu 13.10 and know few HTML editors for it. The editor I use is Bluefish, which has helped me a lot. I am learning Javascript by w3shcool and at the moment I am in the DOM nodes part, and…