Which one is better to use- .after() or .append()


#1

please explain .....


#2

@codeslayer20329,
I think it is better, if one understands the concept.

It all start's with you,
using a Browser
in which you load a HTML-file,
which we will call the HTML-Document.

This document has a minimal build of


<!DOCTYPE html>
  <html>
     <head>
          <title> </title>
     </head>
     <body>
     </body>
  </html>

The Browser =load's= this document into Memory
in a pattern that is described as
the Document Object Model
in short the DOM.
( the interpretation of the DOM is Browser & Version specific )

            html
             |
       +-----+------+
       |            |
     head          body
       |
     title

In the description of your document in DOM-talk...
you will encounter terms like:
parent children sibling descendants ascendants...

The HTML-Element has no parent
but is a parent to 2 child-Element's
the 'head'-Element
and
the 'body'-Element.

The 'head'- and 'body'-Element,
both being children to the 'html'-Element
are siblings to each-other.

The 'head'-Element is parent to the 'title'-Element...
the 'title'-Element is a child of the 'head'-Element
the 'title'-Element is also a descendant of the 'html'-Element.

The DOM has several interface's
over which you can access the data**/**information
held by the DOM.

One of the interface's is the Element-interface
you can divide the interface into
properties ( consisting of a property-key and it's associated VALUE )
and
methods ( giving you the functionality to manipulate the Elements )
https://developer.mozilla.org/en-US/docs/Web/API/Element
https://developer.mozilla.org/en-US/Learn/HTML/HTML_tags


Difference between 'after' and 'append'?
#3

hello @codeslayer20329

.append() insert the content inside an element at last index
.after() insert the content after the element

example

we have this :

with append() :
$("div.a").append("<div class='c'>C</div>");

result :

with after() :
$("div.a").after("<div class='c'>C</div>");

result :


#4

@codeslayer20329,
Now if you do a google search
= discussions / opinions =
jquery append() vs after() site:stackoverflow.com
for instance
= http://stackoverflow.com/questions/14846506/append-prepend-after-and-before

= the Book =
append() site:jquery.com
appendTo() site:jquery.com
after() site:jquery.com
insertAfter() site:jquery.com


Difference between 'after' and 'append'?