I want to create a function and have it return an html like in react (Without use react or jsx)
const func = () => {
return (
<h1>Hello World!</h1>
);
}
I want to create a function and have it return an html like in react (Without use react or jsx)
const func = () => {
return (
<h1>Hello World!</h1>
);
}
Without use react or jsx
If you don't want to use JSX then clearly you can't use JSX. You can return a string:
const func = () => {
return '<h1>Hello World!</h1>';
}
document.querySelector('#test').innerHTML = func();
<div id="test"></div>
Or perhaps an element:
const func = () => {
const el = document.createElement('h1');
el.innerText = 'Hello World!';
return el;
}
document.querySelector('#test').appendChild(func());
<div id="test"></div>