Like XmlNode InsertAfter() , you need to call this method on the generic parent of the node link and insert the node. Try something like this:
Dim NewHTML As HtmlNode = FriendDiv.ParentNode.InsertAfter(HtmlNode, FriendDiv)
Worked well for me. Here is a simple test I did in C # (translated into VB):
Dim html = "<body><div></div></body>" Dim doc As New HtmlDocument() doc.LoadHtml(html) Dim div = doc.DocumentNode.SelectSingleNode("//div") Dim span = HtmlNode.CreateNode("<span class=""label"">Those were the friends</span>") Dim newHtml = div.ParentNode.InsertAfter(span, div) Console.WriteLine(XDocument.Parse(doc.DocumentNode.OuterHtml).ToString())
<span> appears after the <div> in the console.
har07 source share