Questions tagged [dom-manipulation]

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

825 questions
8
votes
3 answers

querySelectorAll: manipulating nodes

As far as I have understood, querySelector returns a real changeable element while querySelectorAll returns a non-live Static Node Set. I want to adjust the style of all elements fitting to a specific selector. It works fine for the first element…
fabb
  • 11,660
  • 13
  • 67
  • 111
8
votes
5 answers

Appended HTML that contains javascript doesn't run, how can I make it run?

I'm appending some HTML containing javascript. T and These two pieces of code are in the big amount of HTML I'm appending. They work…
fmsf
  • 36,317
  • 49
  • 147
  • 195
8
votes
1 answer

Why use ViewContainerRef over *ngif?

I could just do But every document on inserting component in dom dynamically is based on ViewContainerRef. I like what it does. But what makes it so special over…
8
votes
1 answer

Using a jQuery clone outside the DOM

I've been working on a small project where I'm using the jQuery .clone() method. Pitfall with this is using it on HTML that has unique identifiers. So I went on implementing getComputedStyle to find the style properties of the original unique…
Shikkediel
  • 5,195
  • 16
  • 45
  • 77
8
votes
3 answers

How to remove original element after it was cloned?

HTML:

test 1

test 2

test 3

test 4

click
jQuery $('.clickdiv').on('click', function(){ …
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
8
votes
4 answers

How can I highlight a selected list item with jquery?

I have several items in a list and want to highlight the one a user clicks on by applying some css style, maybe a background color etc. My HTML looks like this:
8
votes
3 answers

"jQuery way" to replace just a text node with a mix of HTML and text?

In my web browser userscript project I need to replace just one text node without affecting the other HTML elements under the same parent node as the text. And I need to replace it with more than one node:
foo / bar; baz
hippietrail
  • 15,848
  • 18
  • 99
  • 158
7
votes
3 answers

Changing HTML depending on where I click with javascript/JQuery

In an html page you might have some code with two paragraphs like this:

The first paragraph

The second paragraph


and very simply, these two tags would render like this: The first paragraph The second paragraph What I…
prince
  • 671
  • 2
  • 11
  • 26
7
votes
4 answers

How to prepend text (not HTML) in jQuery?

I realise that I can prepend stuff to an element using: $(...).prepend(myText); However, if myText is, let’s say, "", I actually want that text to appear, but .prepend() would instead prepend an empty span element. What is the recommended way…
Timwi
  • 65,159
  • 33
  • 165
  • 230
7
votes
2 answers

PHP equivalent to jQuery addClass

How would you add a class named newClass to an opening tag like or

using php?

jantimon
  • 36,840
  • 23
  • 122
  • 185
7
votes
1 answer

Update the DOM vs Rerender the View In Angular

I am following https://docs.angularjs.org/guide/scope. 5.The $watch list detects a change on the name property and notifies the interpolation, which in turn updates the DOM. 6.Angular exits the execution context, which in turn exits the keydown…
7
votes
1 answer

Extract element by using document.evaluate()?

I am trying to use document.evaluate() to extract certain child elements out of a element. But I have problems by just extracting the itself. I can extract everything up to the , but no further. For example this works well…
davidkonrad
  • 83,997
  • 17
  • 205
  • 265
7
votes
1 answer

Is there an object in C# that allows for easy management of HTML DOM?

If I have a string that contains the html from a page I just got returned from an HTTP Post, how can I turn that into something that will let me easily traverse the DOM? I figured HtmlDocument object would make sense, but it has no constructor. Are…
Matt
  • 5,547
  • 23
  • 82
  • 121
7
votes
3 answers

Insert after parent of element

What sort of selector would be I need in order to insert after the parent (divouter) of the test3 class in the example below? Thanks.
usertest
  • 27,132
  • 30
  • 72
  • 94
7
votes
5 answers

replace one div with another on hover

I want to replace one div with another when hovering over it. Specifically there will be an average in words, such as "struggling" or "exceeding expectations", and I want to replace this with the numerical average when the user hovers over the…
dax
  • 10,779
  • 8
  • 51
  • 86
1 2
3
54 55