Hello I’m trying to bulid my own function that allows me to create html tags as below , and Im using object as argument to the function
function create_element(arg){
const element = document.createElement(arg.tag);// Create element
if(arg.text){element.innerText = arg.text;} // Add text to element
if(arg.id){element.setAttribute("id",arg.id)} // Add ID
if(arg.hello){
arg.hello = function(x){
console.log(`Hello ${x}`)
}
}
}
create_element({
tag:"div",
id:"id1",
text:"this is a text",
hello:hello("name")
})
my question is how to execute hello function? tag , id and text are working well, thank you kindly.