The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.

learn more… | top users | synonyms

3
votes
1answer
30 views

Adding a class to a root element

I have written some ES2015 JavaScript that adds a class to a root element when one of it's immediate children is focused. Here is the markup for the code to be run on: ...
-1
votes
1answer
89 views

Using templates and function overloads to set DOM attributes [on hold]

I'm making a library to build and manage a website. I want to control what gets to be inserted. For example I don't want to be able to insert ...
2
votes
3answers
72 views

C++ Tree Class implementation

I am trying to implement a class for the Node of a Tree in C++ in order to represent an HTML structure. It is not complete by a shot, but i'd still like an opinion. TreeNode.h : ...
8
votes
1answer
133 views

Animate and play sounds in Simon Says 'the Angular way'

I am a newbie coder and I'm trying to learn good coding habits. I'm making a Simon Says game challenge from Free Code Camp in Angular JS. Codepen I have an array that keeps random integers between ...
2
votes
0answers
15 views

Function to grab all windows and nested windows on a page

I wrote the following function which takes in a window and returns all nested windows on a webpage (I can get all the windows by calling the function with window.top). Is there a more elegant/...
1
vote
2answers
140 views

Tasks organizer app

I've created my first complete JS app, which lets you add tasks and control how much time you spend on them. I posted this to get some ideas how to improve readability, efficiency and the speed of my ...
0
votes
1answer
63 views

Replacing DOM elements that have no attributes

The institution I work for uses an application that has an awful software bug causing useless <code>span</code> tags to appear next to "misspelled" ...
2
votes
1answer
28 views

Sort Facebook Messenger contacts by idle time

I wrote a UserScript that auto-sorts contacts by offline time using the MutationObserver API. I tried to make it as DRY as I could think, and I also tried to make my code as straight-forward as ...
3
votes
0answers
33 views

Simple gallery with scroll

I just created a simple gallery with scroll. Everything works fine but I'm not sure how should I optimize this code: ...
3
votes
1answer
38 views

Google Maps geocoding lookup function

In an effort to keep all of the Google Maps Javascript API in it's own little world, I have created a googleMaps object that will contain all of the functions that directly make google maps webservice ...
10
votes
1answer
170 views

Card-fighting game

I am currently building my first game/app in javascript. It is a very simple script that has about 130~ lines of code. I feel like what I did so far is not optimized, can anyone please help me ...
0
votes
1answer
68 views

Generating HTML code dynamically with jQuery

I am doing a college project and I would like to write my jQuery code following best practices. The project involves using the jQuery .getJSON method to retrieve information from a json file. I have ...
2
votes
2answers
51 views

Tag dependence approach

I need to add class is_active to all div's when I click on <div id="all-tags"> and remove class if I click again. Only ...
6
votes
2answers
71 views

HTML5 sectioning for my design

I've designed my new website: Now I want to build up my HTML as semantic as possible. Here's my first attempt / set-up: ...
3
votes
1answer
76 views

Editing HTML based on instructions in a data structure

My getExtend() function, which will be included via require.js, has two inputs and one output: HTML file content config object which determine how to ...
0
votes
1answer
22 views

iframe play & thumbnail function

This is quite a simple function, but I just wanted some opinions on it, like is this the correct way to run a function and check if an element exists or not? ...
0
votes
1answer
59 views

Manipulate original DOM in React.js

As an introduction, I would like to have my inputs validated with the built-in validation HTML5 attributes, e.g. use pattern for text input. So this is my sample code that implements that. Is it ...
6
votes
1answer
51 views

Adding a replica of some DOM elements on click

I have the following code which inserts a new element of the same type over and over again to the parent element. I am new to JavaScript so was wondering if there was a better way of doing this. I ...
2
votes
1answer
47 views

Custom each method

I have developed the following method for each as a replacement for $.each, and I am considering using it in my personal lightweight js library called LIBJS. The final version will be part of a ...
2
votes
1answer
135 views

Remove the object's sibling on click

In my program below I am getting the parent node game 1 and then removing one of the two child nodes, depending on which one is clicked. I currently have two event ...
3
votes
1answer
49 views

Renaming the iframe src attribute to facilitate lazy loading

I'm not great with javascript. I need some code to rename all iframe src attribute names to data-src, for a lazyload plugin to ...
6
votes
1answer
92 views

Script to pick random answers for a vocabulary quiz

I am making a small script, which, when run in the console on Vocabulary.com, picks one answer (the third or fourth) and clicks. Then the code checks if the answer was wrong or right and goes to the ...
1
vote
2answers
68 views

Keyboard handler to move a shape in response to arrow keys

I finished Codeacademy and I'm looking to practice and get better at JavaScript. Is this coded correctly or should I have made a function for it somehow? The purpose of this code is to move a square ...
3
votes
1answer
45 views

Minimalist HyperScript implementation

I've tried to roll out my own HyperScript implementation. I would be interested in any suggestions to improve it or point me to any other better implementation which is still maintained. I checked the ...
1
vote
3answers
75 views

JavaScript for toggling appearance

I have a dedicated stylesheet <style id="dynamicStyles"></style> for my page's dynamic styles. They are controlled by this JavaScript: ...
1
vote
1answer
31 views
0
votes
0answers
33 views

PHP FormBuilder class

I've taken some suggestions from this question and tried to build my own FormBuilder class. It's supposed to work like this: Creates an object of type form ...
1
vote
0answers
29 views

Large table updates using AJAX in Internet Explorer 11 (Cont'd)

Previous topic: Large table updates using AJAX in Internet Explorer 11 For the functions included here, I have taken the advice of the previous answer and incorporated it in the restructure, but am ...
2
votes
1answer
70 views

Generating calendar months for a datepicker

I got a problem I'm finding pretty hard to solve. I'm trying to generate calendar months for a datepicker but at only 12 months I see a perf of around ~4-7ms. This doesn't sound like a problem but it ...
1
vote
0answers
71 views

Angular resize directive

I have created this directive in Angular. The idea is to calculate width of height and height of specific element via style function attached to ng-style on the same element. The directive uses ...
1
vote
3answers
76 views
6
votes
2answers
88 views

Hours:Minutes Addition

I wrote this simple page to help at work, and as an exercise to get more familiar with JavaScript. I'm especially interested in help with style and structure - is this "standard"? I know the input ...
2
votes
2answers
74 views

Extracting distinct HTML list items into a JavaScript array

This code is made to generate a list of unique elements of the array made of the other two arrays. The fact that we need two lists to convert in two different array is part of the task. This code ...
1
vote
1answer
23 views

Checking if a tag is on the screen

This function receives an HTMLElement as an argument and returns true if the tag is on the screen and ...
3
votes
1answer
99 views

Animating sprite without libraries

I'm building a small game in pure JS for my own learning purposes, using sprites to model players. Before I go further, I want to try to get the animation down. The below code should produce a blank ...
1
vote
1answer
31 views

Scrolling with an easing function

I wanted to write a function that when invoked, will scroll the page downwards in a smooth fashion. Comments and criticism welcome. I don't like, for example that determining whether it is done is ...
1
vote
3answers
100 views
3
votes
2answers
157 views

Dynamically creating elements with an object constructor

Just experimenting with various Javascript techniques and was wondering if the code below is valid and if there are any disadvantages to using this technique to create html tags from JS object ...
3
votes
2answers
63 views

Show and hide posts using setTimeout

I have made an effect that has the h1 move and then reveals p using .addClass, ...
7
votes
1answer
1k views

Converting partial XML (Node List) to a String

I have a need to extract a part of XML tree (everything under root) and convert it to a string. (The result string will be later pasted inside ...
11
votes
2answers
143 views

Early Access: Dynamically expanding input element table

This code is in a really early state in the lifecycle. I'm still in the process of implementing some core features, but nevertheless the code up to here works and accomplishes its task. I have no ...
12
votes
3answers
931 views

Lights on: playing with buttons in Javascript

First play with the game a little bit, and it is quite fun (a little hard but very satisfying when you win, be sure to put it full page): ...
4
votes
1answer
67 views

Limiting the number of text fields created

I need to make sure that the max of text fields created is limited to 10 at most. It's a script that I've ripped off elsewhere, and have modified it via help from StackOverflow on a couple of other ...
3
votes
1answer
5k views

HTML and JS to dynamically load, refresh, and execute JavaScript from external file

The following code is designed to load and refresh JavaScript code from an external file sandbox.js and allow it to be refreshed dynamically and executed without ...
2
votes
1answer
74 views

jsonToDOM Function

For the MDN documentation website we have written this jsonToDOM function and I was wondering how you all would improve it. It takes a json structure and creates ...
4
votes
1answer
90 views

Generate form and append to the body

I'm writing a plugin and want it to have no dependencies. I create a form and append it to the page, but the code is really long. Does anyone have any suggestions to clean it up, perhaps shortening it?...
1
vote
1answer
87 views

Organize dynamic HTML generation function for audio player

I have some code that's part of my music-js library, and most of it is very organized, using object-oriented design for my AudioAnalyser and ...
2
votes
1answer
295 views

Use DOM and XPath to make some changes in HTML document

I intend to make some changes in an HTML document, like remove, replace, append some nodes. I have several arrays with same structure like the following example ...
4
votes
1answer
251 views

Sending Ajax requests and updating DOM

I wrote some ugly JavaScript that is responsible for sending Ajax requests and update the DOM. I'm using it to show user progress of background jobs. ...
1
vote
0answers
47 views

Appending a group name to each committee member

I wrote this script to get text, if it equals, append the name of the group to a person's information. I know using .each() is gpu intensive and this feels like a ...