English 中文(简体)
不得在另一节之前和之后插入一栏
原标题:Cannot insert a node both before and after another node

I m trying to insert a node both before and after a existing node. The problem is, it will only insert one of them. Odd. Can anyone explain why?

这里的法典

// create your new node <p>Hi</p>
 var newNode = document.createElement("p");
 newNode.appendChild(document.createTextNode("Hi"));

// a existing node for reference
var refNode = document.getElementById("xyz");

// insert newNode before refNode
refNode.parentNode.insertBefore(newNode, refNode);

// insert newNode after refNode
refNode.parentNode.insertBefore(newNode, refNode.nextSibling);

PS 感谢karim79。 回答我的之后插入的序言问题。

最佳回答

当你在文件上添加一个节点时,必须将其从以前的任何地点删除。 同一节点不能在两个地点。

你们想要的是第二处点 no子的复印件:

// create your new node <p>Hi</p>
var newNode = document.createElement("p");
newNode.innerHTML = "Hi";

// a existing node for reference
var refNode = document.getElementById("xyz");

// insert newNode before refNode
refNode.parentNode.insertBefore(newNode, refNode);

// insert newNode after refNode
refNode.parentNode.insertBefore(newNode.cloneNode(true), refNode.nextSibling);
问题回答

只有一个<代码>新编号。 插入斜体,环绕。

insert after (single llinked list list node *previous,single linked list node*new node)
     {
  if(new node==null)
    return;
else{
    if(previous==null)
    add first(new node);
else{
   single linked list node*nex=previous->;
   previous->next=new node;
   new node-> next=next;
      }
    }
  } 




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签