Home > front end >  Trouble ask how to delete nodes inside the text node child
Trouble ask how to delete nodes inside the text node child

Time:10-06

I want to delete the inside of the node a child node, child nodes including the checkbox button text, both in front of the ID can be deleted, how to find the text deleted ah
Var oCheckbox=document. The createElement method (" input ");
Var oButton=document. The createElement method (" input ");
Var br=document. The createElement method (" br ");
Var myText=document. CreateTextNode (result [I] cname);
OCheckbox. SetAttribute (" type ", "checkbox");
OCheckbox. SetAttribute (" id ", result [I] cname);
OButton. SetAttribute (" type ", "button");
OButton. SetAttribute (" value ", "x");
OButton. SetAttribute (" id ", "BTN" + result [I] cname);
Var mydiv=document. GetElementById (" Info ");
Mydiv. The appendChild (oCheckbox);
Mydiv. The appendChild (myText);
Mydiv. The appendChild (oButton);
Mydiv. The appendChild (br);
Id=[I] result [I] a cname.


For (var k=0; K
(function (k) {

Var num=k;

Document. The getElementById (" BTN "+ id (num)). The onclick=function () {




Mydiv. RemoveChild (document. GetElementById (id (num)));
Mydiv. RemoveChild (document. GetElementById (" BTN "+ id (num)));


}
}) (k)
}

CodePudding user response:

Ky find brothers or parent node said the last child node

CodePudding user response:

According to the position that you add nodes, through has access to the node to find the relationship between ah,
For example, the text is the checkbox next siblings
Mydiv. RemoveChild (document. GetElementById (num) (id) nextSibling);

CodePudding user response:

Have a special way to get the text node of jquery is $(' '). The text (); Language is the js textNode
But opportunistic way is: to the text contained in & lt; Span> Add an id tag is not just a matter of
  • Related