Thanks
I am trying to detect Which image id="" was clicked ?
Pls , how can I do that ?
Run code here:
https://vmars.us/ShowMe/function-fireContextMenu-2-IMAGES.html
There are 2 images :
Here is where in code I want to do it :
FULL CODE:
Thanks for your Help..
I am trying to detect Which image id="" was clicked ?
Pls , how can I do that ?
Run code here:
https://vmars.us/ShowMe/function-fireContextMenu-2-IMAGES.html
There are 2 images :
Code:
<span class="a"><div class="hero" id="elem1"><img style="z-index:800; width:32px; height:32px; " src="1-Red-Circle-Transp.png" ></div> <!-- -->
</span>
<span class="a"><div class="hero draggable" id="elem2"><img class="draggable"; style="z-index:500; width:20px; height:20px;" src="naturalAccidental-Grey-vm.png"></div> <!-- -->
</span>
Here is where in code I want to do it :
Code:
function fireContextMenu(event) {
event.preventDefault();
console.log("function fireContextMenu( )")
console.log("event.target.id = " + event.target.id)
// if element.id = "elem1" {
element.id = document.getElementById("elem1").innerHTML
console.log("element.id = " + element.id)
FULL CODE:
Code:
<!DOCTYPE html>
<!-- saved from url=(0043)https://en.js.cx/task/drag-heroes/solution/ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>file:///C:/PureBasic-myApps/vmProjects/BUTTONS/Guitar-Scales-and-Boxes/DnD.en.js.cx-Super-Heroes/en.js.cx-task-DnD-Multi-Items-WORKING-TRY-STUFF-01.html</title>
<style>
html, body {
margin: 0;
padding: 0;
}
span.a {
display: inline-block;
// width: 100px;
// height: 100px;
padding: 2px;
// border: 1px solid blue;
// background-color: yellow;
}
.hero {
#hero1 , #elem1{
// background-position: 0 0;
//position:absolute;
top: 250px;
// left: 250px:
width: 24px;
width: 24px;
z-index: 1000;
float: left;}
#hero2 #elem2{
// background-position: 0 -128px;
width:24px;
width:24px;
z-index: 500;
//position:absolute;
top: 250px;
float: left;}
.draggable {
cursor: pointer;
}
#hr01 {
}
</style>
</head>
<body>
<br><br><br><br>
<div id="imagesContainer" style=" width:100%; height:100px; border-style: dotted; border-size:4px;">
<span class="a"><div class="hero" id="elem1"><img style="z-index:800; width:32px; height:32px; " src="1-Red-Circle-Transp.png" ></div> <!-- -->
</span>
<span class="a"><div class="hero draggable" id="elem2"><img class="draggable"; style="z-index:500; width:20px; height:20px;" src="naturalAccidental-Grey-vm.png"></div> <!-- -->
</span>
</div> <!-- id="imagesContainer" -->
<hr id="hr01">
<div style="clear:both"></div>
<script>
var elemNumber = 0;
var element = "";
// =================================================
document.addEventListener('contextmenu', fireContextMenu);
// This function will be called whenever contextmenu event occurs
function fireContextMenu(event) {
event.preventDefault();
console.log("function fireContextMenu( )")
console.log("event.target.id = " + event.target.id)
// if element.id = "elem1" {
element.id = document.getElementById("elem1").innerHTML
console.log("element.id = " + element.id)
//function cloneElem1(){
// Get the element
var elem = document.querySelector('#elem1');
//console.log(elem);
// Create a copy of it
var clone = elem.cloneNode(true);
clone.addEventListener("dragstart", (event) => { drag(event); });
// Update the ID and add a class
clone.id = 'elem1' + elemNumber;
clone.draggable = 'true';
clone.onclick = "helloConsole()"
clone.zIndex = elemNumber;
elemNumber = elemNumber + 1
// Inject it into the DOM
hr01.after(clone);
//function cloneElem1()
}
// =================================================
</script>
</body></html>
Thanks for your Help..