function
setup() {
createCanvas(550, 300);
textSize(18);
text(
"Click on the button to create a new "
+
"element with the given ID"
, 20, 20);
setBtn =
createButton(
"Create new Element with ID"
);
setBtn.position(30, 40);
setBtn.mouseClicked(createNewElement);
setBtn =
createButton(
"Show Last Element ID"
);
setBtn.position(300, 40);
setBtn.mouseClicked(showID);
id_name = createInput(
'tmpID'
);
id_name.position(30, 80);
}
function
createNewElement() {
clear();
tmpElement = createElement(
"p"
);
let idToSet = id_name.value();
tmpElement.id(idToSet);
text(
"New element created with ID: "
+
idToSet, 30, 120);
text(
"Click on the button to create a new "
+
"element with the given ID"
, 20, 20);
}
function
showID() {
clear();
let setID = tmpElement.id();
text(
"The ID of the last element is: "
+
setID, 30, 120);
text(
"Click on the button to create a new "
+
"element with the given ID"
, 20, 20);
}