el.email = input(props({ type: 'email' }))
better or easier than: <input type="email">
I think the example needs to be more compelling. el.email = input(props({ type: 'email' }))
better or easier than: <input type="email">
I think the example needs to be more compelling. el.email = (function(){
var input = document.createElement('input');
input.type = "email";
return input;
})();
...or something similar. Your could also use createContextualFragement or a little function that uses innerHTML, both of which parse a string into HTML (which is problematic). Or you could use a templating library, of which there are many and this is one. el.email = document.createElement('input');
el.email.type = "email"; el.email = Object.assign(document.createElement('input'),{type:'email'});Also used was object destructuring: http://odetocode.com/blogs/scott/archive/2014/09/11/features...
If anything it should be `var email = {...document.createElement('input'), type: 'email'}`
But that would result in `Object.assign({}, document.createElement('input'), { type: 'email' })`
Got 4 up votes though..
There is rarely a reason to build HTML using createElement, it's only sometimes needed. The majority of the time just write HTML - it's much easier.
> Or you could use a templating library
Or just use the built in <template> tag.
yes, almost by a factor of 4 :D
check out "render" test cases:
https://cdn.rawgit.com/localvoid/dd96890b82f1d1268df34330b14...
If you're a JS programmer you should definitely read Crockford's famous JS book, it explains a lot of JS patterns and the rationale behind them.
var input = crel('input', {type:'email'});
vs:
var wrapper = document.createElement('div'); wrapper.innerHTML = '<input type="email">'; var input = wrapper.children[0];