Questions tagged [dom]

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.

Filter by
Sorted by
Tagged with
3
votes
1answer
511 views

First attempt at MVC JavaScript pattern

I would really appreciate a review of my interpretation of MVC here. It's as bare bones and clear as possible. I've based it on some in-depth reading but I don't know if I have understood everything ...
4
votes
4answers
2k views

My first javascript sorting

I started learning JavaScript a week ago, and I made a sorting function on my own. It does work, but I need reviews and how to write a better one. ...
12
votes
3answers
7k views

Implementing an algorithm that walks the DOM without recursion

Here's a simple algorithm that walks the DOM given a node: ...
3
votes
1answer
198 views

Javascript Form Manipulator Code Review

I'd appreciate a review of at least some of this javascript, if anyone has time. It's really long, but I think it's useful. It's designed to let you create forms and do javascripty things by only ...
3
votes
1answer
6k views

Optimize Recursive Function to traverse nested DOM nodes

I wrote a recursive function that traverses nested DOM nodes of the following form: ...
3
votes
1answer
447 views

eDomForm - dynamic forms without writing any JavaScript

I'd like some comments and any suggestions that you have for where to go next with this. I've been working on developing a JavaScript library that allows for dynamic forms by simply adding some extra ...
3
votes
1answer
200 views

String processing in JavaScript

We have a lot of phone numbers that contain dashes and start with a zero which are from another country. I am trying to strip the dashes and the one leading zero and select the country code from a ...
5
votes
2answers
338 views

OOP approach to using DOMDocument

I've tried to write an "OOP" approach to printing a website using the DOMDocument class. I'm kind of stuck here because I feel like I am blundering in how I am passing and using the DOMDocument. I ...
1
vote
1answer
643 views

Better way to hide, change and show DIVs in Javascript

I made this Javascript to hide, show and change some DIVs but I believe it's not really good code. Can you help me to make it better? ...
2
votes
1answer
83 views

when we need to add some javascript code to html, where we have to put it?

when we need to add some javascript code to html, where we have to put it? What is the best practice: in line: ...
8
votes
1answer
693 views

Very fast query selector

A few months ago, I wrote a query selector that seems to outperform the query selectors in the popular GP libraries by a pretty hefty margin. I'm wondering if I overlooked something. It seems odd that ...
8
votes
2answers
201 views

Switching some text labels when the first image of a carousel is active

Is there any way I can simplify this inefficient piece of JavaScript? ...
0
votes
2answers
4k views

Render Large jQuery Mobile Listview

I am trying to write an efficient loop for rendering a jQuery Mobile listview. Is this the most efficient loop? I append elements 100 at a time to try and allow the user to see progress without ...
9
votes
5answers
169k views

Get the value of the name attribute of each element with class=“class”

I need a function to get the value of the name attribute of each element with class="class". I was wondering what is the best way to do this, performance-wise. Currently I'm using jQuery and doing it ...
1
vote
1answer
420 views

Website with images that pan to different sides

I've just started programming with JavaScript and I am currently working on this hobby website project of mine. The site is supposed to display pages filled with product images than can be "panned" to ...
4
votes
1answer
6k views

Stripping formatting from text - Am I using an efficient jQuery selector?

I'm making a comment box using a contenteditable div, but I want to remove formatting from text a user might copy/paste into it (also no CTRL+B or CTRL+I shortcuts allowed either). Only "approved" ...
1
vote
1answer
214 views

Javascript looping fader animation

Here's a small module I've written that implements an animation which fades through the child elements in a container div on a continual loop. I realise I could have done this way quicker using ...
10
votes
3answers
3k views

Efficient string concatenations with DOM

I form DOM nodes as strings and append them to DOM tree like below using jQuery. ...
1
vote
2answers
8k views

Creating input when checking/clicking radio button

I'm new to jQuery and played a bit with what can I do with radio button. I want to create ONLY one input type when I click the Notice radio button. I already using many way to achieve this, but this ...
4
votes
4answers
405 views

What is the shortest snippet that emulates `include` in JavaScript without third-party scripts?

JavaScript doesn't offer a module system. There are many third-party solutions, like require.js or jQuery's $.getScript. Most, ...
5
votes
4answers
4k views

Counting thousands of selected checkboxes

This is a script I use to count how many items are selected in a form. It currently loops through the entire form to count how many check boxes are selected, each time a checkbox is clicked. The form ...
3
votes
3answers
189 views

Populating two lists, each from their respective with user input field

I've simplified this for posting, since there are going to be more than 4 options sets for this function to cycle through: ...
4
votes
1answer
1k views

Simple DOM mutation abstraction

Background: I need to use mutation observers to watch for nodes being added/removed under a specific element. The code below is an attempt to implement something re-usable that uses ...
2
votes
2answers
63 views

Selector targets overly obtuse - recommendations?

This presumably simple task resulted in much more scripting logic than I thought would be necessary. Goal: when the user clicks a button inside one of the divs, it affects said div. Issues: I did ...
2
votes
2answers
123 views

An “Add” button that clones an item, and a “Remove” button that fades and removes an item

I was looking into removing multiple inputs and selects at once using jQuery, but I couldn't find a solution, so I ended up with the following code: ...
8
votes
2answers
34k views

JavaScript function to get DOM elements by any attribute

I needed to write a function today in JavaScript that would return all elements based on a given attribute. e.g retrieve all elements that have an id attribute in them. The function I wrote for ...
3
votes
2answers
474 views

Showing an item in a shopping cart

I'm updating and old project from jQuery 1.4 to jQuery 1.7. Can this be simplified, thus reducing the amount of code, and perhaps in such reduction, have it improved? Having the following code: <...
2
votes
2answers
2k views

Looping through DOM to modify elements

I'm using this PHP to modify A elements in a DOM fragment (a vBulletin $post['message'] if that matters) so that links to external sites always open new tabs. This ...
1
vote
1answer
6k views

Detecting when the contents of a web page changes

This is the code I'm using at the moment ...
1
vote
2answers
141 views

Can I adjust this code which displays a table to run faster?

...
7
votes
3answers
3k views

Handling various types of nodes when traversing a DOM tree

How to minimize the following code using java's features ... looking for some workaround with the switch-case statement I've seen several question regarding switch-case design pattern / best ...
2
votes
2answers
190 views

Sanitize DOM IDs

I needed to create a method that would sanitize DOM IDs based on the HTML 4 criteria (yeah, HTML 5 is a lot looser). Does this make sense? Did I get too cute with making it concise? Am I totally ...
5
votes
1answer
150 views

Altering contents when loading iframes

I am quite new to JavaScript and I wonder if you experts can see any obvious mistakes in this working code, and if any, suggest good improvements. ...
5
votes
3answers
373 views

Rendering three types of events as HTML elements

I have to clean up some Javascript and I am trying to figure out a more elegant way to write this code below. It's basically looping through 3 dictionaries with the same loop structure and appending ...
11
votes
4answers
312 views

Application that creates a toolbar to show/hide elements on a page

I've been spending a lot of time reading about JavaScript lately, and this is my first piece code that I've tried to apply some of what I've read to. I'm trying to stay clear of using a framework for ...
3
votes
3answers
470 views

Dynamic Tooltip Generator

In this project I've taken my first shot at OO JavaScript, and I'm not sure how it turned out. The script dynamically makes a tooltip with different text if you so choose. As of now it takes a lot to ...
27
votes
4answers
4k views

Self-playing Baseball game

The Demo for what I have made is located here Basically I am trying to make a self playing JavaScript baseball game with the use of no libraries. Is there anything I could improve on in the code? <...

1
4 5 6 7
8