Questions tagged [insertadjacenthtml]

60 questions
3
votes
1 answer

How to remove elements after an element in JavaScript

In my current project i am getting xhr requests and i am placing them after an element like with this: el.insertAdjacentHTML('afterend', "foo bar"); but i haven't found a way to remove everything after the given element, otherwise the markup will…
Sascha Grindau
  • 418
  • 2
  • 6
  • 18
3
votes
1 answer

React render insert adjacent element

How do I specify position relative to the element when calling React render on an element and its container? i.e. ReactDOM.render(element, document.getElementById('divInTheBody')); Say I want to insert this element before the element itself…
Ridhwaan Shakeel
  • 981
  • 1
  • 20
  • 39
2
votes
2 answers

select element that is created by insertAdjacentHTML for adding or remove class

guys i want to add one class to li Element aftet it is created through insertAdjacentHTML but i dont know how i can select it in fact i replaced insertAdjacentHTML way with append that i commented appen way; my codes are: function…
joyi61
  • 41
  • 4
2
votes
1 answer

Changing className after insertAdjacentHTML

I am trying to change my className after the insertAdjacentHTML() function. I am using an AJAX request for this and the route /reviewcombine is from my backend JavaScript codes. My codes:
CBCH
  • 127
  • 1
  • 3
  • 14
2
votes
2 answers

Inserting element into DOM at a specific place is not working

I would like to insert an input type=text field between p and input type=submit using insertAdjacentHTML, but it’s not working. A string [object HTMLInputElement] gets inserted instead of an input element. What am I missing? Please share if there…
Tzar
  • 5,132
  • 4
  • 23
  • 57
2
votes
2 answers

javascript: get random pairs of an array without duplicates

I have an array of students, that should be random paired by clicking the button "button-newPairs". These pairs should be shown in 8 divs "pair one", "pair two", ... that contains two spans "studentOne" and "studentTwo". I get the pairs in console…
Fine
  • 47
  • 7
1
vote
1 answer

insertAdjacentElement adds only one element, when insertAdjacentHTML adds four

So i wanted my webpage to create one dot button for every photo that was placed by me in a slides NodeList. Instead, it just creates just one dot, just like if there was just one image, but there are 4 images actually. const dotContainer =…
1
vote
1 answer

How can I render html with insertAdjacentHTML

How can I render components with pure javascript? I used insertAdjacentHTML and forEach to render a list with objects but the objects appeared undefined. object list const liRender = document.getElementById('ul-component') function render()…
Davi Roque
  • 25
  • 4
1
vote
1 answer

How to insertAdjacentHTML between 2 different divs

I need to get my div between 2 divs inside my template. I can only edit it with external HTML, JS. Template looks like this:
XXX
And I need to…
LM Rig
  • 21
  • 6
1
vote
3 answers

encapsulate element by html tag

I have this code and it runs as i want. The goal is to encapsulate the element ("TEST") with bold tag . I just want to know if there any single builtin method to encapsulate element by html tag? something like insertAdjacentHTML , but the…
andio
  • 1,574
  • 9
  • 26
  • 45
1
vote
2 answers

react-jsx-parser can't map content

I'm using the react-jsx-parser npm package and I have this code: Builder.tsx import JsxParser from "react-jsx-parser"; export default function Builder() { const a = ` <> {data.map((el, i) => (
1
vote
0 answers

Waiting for insertAdjacentHTML function to complete creation

I am creating a paragraph dynamically adding it and then assigning an id to it. While the paragraph gets created, the id does not. I have kept an alert which returns undefined. This is possibly because the code for creating the id gets executed…
oTwo
  • 185
  • 2
  • 13
1
vote
0 answers

Cannot read property 'insertAdjacentHTML' of null

When I try rendering a new job to the DOM, the above error is displayed. The template literals select data from the getJob() function in my Job.js file. The id selection works when I click on a specific job from a query search. The below elements…
1
vote
1 answer

insertAdjacentHTML wipes functions off page same as document.write

I had a previous question, and someone told me that document.write wipes all functions out, and to use insertAdjacentHTML instead, but when I tried it, it has the same result. The code still says that myFunction is not defined. What am I doing…
1
2 3 4