Questions tagged [dom-manipulation]

The process of changing the Document Object Model (DOM). It includes adding, removing or changing DOM elements.

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

jQuery how to remove all tags from a

I've tried both of the following but none of them worked: $('#divhtml').remove('span') $('#divhtml').find('span').remove() EDIT: $('#divhtml').find('span').remove() worked on 2nd try.
Laguna
  • 3,706
  • 5
  • 27
  • 42
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

remove 3 last divs with jQuery

1
2
3
4
5
6
7
How to remove the 3 last div ? I tryed…
zep
  • 133
  • 1
  • 1
  • 4
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
1
2
3
54 55