-1

What is the reason I don't have to include the jQuery library. To use the method. I want to append an element after the h1.

The h1 is in between other child elements.

const contentDivH1 = document.getElementById('content').children[2];
const svgElement = document.createElement('svg');

iife to append after h1 the svg element

(() => contentDivH1.after(svgElement))()

It worked but why?

thanks to @Quentin: .after() is part of the DOM API, not native JS.

Ilger
  • 1
  • 2

1 Answers1

0

.after() is a method. If it exists or not depends entirely on what object you are calling it on.

There is an after method defined in jQuery.

There is also an after method defined in DOM, although it is experimental.

They two methods behave differently.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335