Thanks for your Help…
Having Problems with Create newElement:
10-CIRCLES-ONLY-FRETBOARD-1-IMAGE-CREATE-ELEMENTS.html:361 Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 2 is not of type 'Node'.
var elemNumber = 1;
var elemBgColor ; //
var floatLeft = "float:left" //
var createId ;
var holdID;
// =================================================
document.addEventListener('contextmenu', fireContextMenu);
// This function will be called whenever contextmenu event occurs
function fireContextMenu(event) {
event.preventDefault();
holdID = event.target.id
console.log("holdID = " + holdID) ;
if (holdID == "elem1" || holdID == "elem2" || holdID == "elem3" || holdID == "elem4" || holdID == "elem5"
|| holdID == "elem6" || holdID == "elem7" || holdID == "elem8" || holdID == "elem9" || holdID == "elem10")
{ console.log("Yep , " + holdID + " is Clone-able !") ;
}else{
console.log("NOPE , " + holdID + " is NOT Clone-able !") ;
return ;
}
//Update the ID and add a class
holdID = 'elem2' + elemNumber;
console.log("New holdID = " + holdID)
elemNumber = elemNumber + 1
var elemName = elemName + elemNumber ;
var newElement = document.createElement(elemName);
newElement.zIndex = elemNumber;
// Inject it into the DOM
let NodeName = document.getElementById("hr02").nodeName;
console.log("NodeName = " + NodeName) ;
document.body.insertBefore(newElement, NodeName); // prob #1
}
Uncaught DOMException: Failed to execute ‘insertBefore’ on ‘Node’:
The node before which the new node is to be inserted is not a child of this node.
at HTMLDocument.fireContextMenu
What does that mean ?
var catchFirstTimeThru = 0 ;
var elemNumber = 1;
var elemName ;
var NodeName ;
var elemBgColor ; //
var floatLeft = "float:left" //
var createId ;
var holdID;
// =================================================
document.addEventListener('contextmenu', fireContextMenu);
// This function will be called whenever contextmenu event occurs
function fireContextMenu(event) {
event.preventDefault();
catchFirstTimeThru = catchFirstTimeThru + 1
if (catchFirstTimeThru <= 1) { return ; } ;
console.log("catchFirstTimeThru = " + catchFirstTimeThru ) ;
holdID = event.target.id
console.log("holdID = " + holdID) ;
if (holdID == "elem1" || holdID == "elem2" || holdID == "elem3" || holdID == "elem4" || holdID == "elem5"
|| holdID == "elem6" || holdID == "elem7" || holdID == "elem8" || holdID == "elem9" || holdID == "elem10")
{ console.log("Yep , " + holdID + " is Clone-able !") ;
}else{
console.log("NOPE , " + holdID + " is NOT Clone-able !") ;
return ;
}
// Name a New Element
holdID = 'elem2' + elemNumber;
console.log("New holdID = " + holdID)
elemNumber = elemNumber + 1
elemName = elemName + elemNumber ;
console.log("elemName = " + elemName) ;
newElement = document.createElement("div");
newElement.zIndex = elemNumber;
// Inject it into the DOM
//NodeName = document.getElementById("hr02").nodeName;
var x = document.querySelectorAll("hr");
NodeName = x[1];
console.log("NodeName = " + NodeName) ;
document.body.insertBefore(newElement, NodeName); // line # 369
//document.body.insertBefore(newElement, newElement);
}
<!-- **What I want to do is Create a New one of these:** -->
<div class="item" id="elem1" style=" position: relative; float:left; left: 30%; top:0; background-color: #FF0004;" > 1</div>
<!-- -->
<div class="item" id="elem2" style=" position: relative; float:left; left: 31%; top: 0; background-color: #FE8E05;" > 2</div>
In document.body.insertBefore(newElement, NodeName); the document.body part needs to be the parent of NodeName. The MDN docs are a little vague on this so I wouldnt blame ya for not getting it. The easiest way to do it is NodeName.parentNode.insertBefore(newElement, NodeName);
[quote=“PAEz, post:4, topic:656450”]
NodeName.parentNode.insertBefore(newElement, NodeName);[/quote]
Awesome Help…
Thank you:
Everything above is working now . https://www.vmars.us/Guitar/10-CIRCLES-1-IMAGE-CREATE-ELEMENTS-ondragover-Prob.html
The only thing that’s not working is ondragover ondrop image .
No ERROR messages , and the ‘+’ sign shows-up , but can’t drop on image .
Here is the code: