The process of changing the Document Object Model (DOM). It includes adding, removing or changing DOM elements.
Questions tagged [dom-manipulation]
825 questions
24
votes
3 answers
Add line breaks or spaces between elements when using jQuery .append()
I have a jQuery set of elements that I get from my DOM by calling:
$(".some-selector");
All my elements are DIVs each in its own line. My DIVs are set CSS (among other things)
display: inline-block;
which prevents them from rendering as block…

Robert Koritnik
- 103,639
- 52
- 277
- 404
21
votes
1 answer
Using RegExp to dynamically create a Regular Expression, and filter content
I am struggling with using the RegExp object to allow me to dynamically create an expression, and apply it to a group of elements.
Here is a jsFiddle, below is the code:

Mild Fuzz
- 29,463
- 31
- 100
- 148
17
votes
2 answers
Where does DOM manipulation belong in Angular 2?
In Angular 1 all DOM manipulation should be done in directives to ensure proper testability, but what about Angular 2? How has this changed?
I've been searching for good articles or any information at all about where to put DOM manipulation and how…

Chrillewoodz
- 27,055
- 21
- 92
- 175
16
votes
2 answers
16
votes
1 answer
Knockout components (not) binding on new content
Redacted question and example
I'm trying to get Knockout components to bind after the initial ko.applyBindings(); so I can add custom elements dynamically.
In my original post I referred to loading content by ajax, but my problem occurs when custom…

rwalter
- 891
- 1
- 7
- 19
16
votes
4 answers
Which is better: string html generation or jquery DOM element creation?
Ok, I'm rewriting some vanilla JS functions in my current project, and I'm at a point where there's a lot of HTML being generated for tooltips etc.
My question is, is it better/preferred to do this:
var html = '
Some More…

Ed James
- 10,385
- 16
- 71
- 103
16
votes
3 answers
Load AngularJS Template within page, dynamically
I have a page containing 2 controllers: one which manages a list of so-called 'apps', and another that is to place the new Angular template into the innerHTML of its Div element.
…

Zoey
- 2,391
- 2
- 22
- 28
16
votes
4 answers
Create a label using jQuery on the fly
I need to create a label and text field on the fly and also include datepicker for the textfield. I need something like this:
I have tried something like this in…

user525146
- 3,918
- 14
- 60
- 103
14
votes
2 answers
Slicing HTML based on delimiter
I am converting Word docs on the fly to HTML and needing to parse said HTML based on a delimiter. For example:
[[delimiter]]Start of content section 1.
…

user8488500
- 141
- 1
- 4
13
votes
1 answer
13
votes
4 answers
How can I Observe the contents of an 'a' tag - jquery
I have a blank tag that content is loaded into via an external piece of javascript. I want to observe the and when its content changes perform another task. The content will only ever change once.
Can this be done?
I am using also using…

Lizard
- 43,732
- 39
- 106
- 167
12
votes
1 answer
Performance of getElementById vs. getElementsByClassName vs. querySelector
I was reading about dom manipulation topic in dev.mozilla and I came across with a statement that suggest us to use querySelector for element selection:
Note that, as with many things in JavaScript, there are many ways to
select an element and…

brainoverflow98
- 1,138
- 11
- 28
12
votes
5 answers
Appending a DOM element twice (jQuery)
Can someone explain why the following snippet does not add to both #a and #b?
HTML:
JS:
$(function(){
var $foo = $("HI ");
$("#a").append($foo);
…

parsa
- 2,628
- 3
- 34
- 44
9
votes
6 answers
Change the tag but keep the attributes and content -- jQuery/Javascript
Text
changed to
Text
I'm familiar with jQuery's replaceWith but that doesn't keep attributes/content as far as I know. Note: Why…
Kyle Cureau
- 19,028
- 23
- 75
- 104
9
votes
4 answers
"virtual" dom manipulation?
I know that doing multiple dom manipulations is bad as it forces multiple repaints.
I.e:
$('body').append('')
.append('')
.append('')
.append('');
Instead a better practise is…

Hailwood
- 89,623
- 107
- 270
- 423