I'm developing an application that uses a lot of Jquery, since there are several very specific functions.
But for the sake of customization and optimization, I managed to mix some searches to create "my own lib" in a very simplistic way, not too much, just to perform functions on the front end that stylize the site from a standard of his own. The link for a part of it is here on gitHub .
And I created the .newElement()
function, which in the case below works perfectly.
var div = M('div');
div.css({
width: '100px',
padding: '10px',
background: "#333"
})
var a = div.newElement('a');
a.css({
color: 'white'
})
a.html('Exemplo')
a.attrs({
href: "https://jsfiddle.net/",
target: "_blank"
})
<script src="https://rawgit.com/samirbraga/libM/master/mlib.js"></script><div></div>
However,whenItrytocreatemorethanonechildtothesameelement,Ihaveaproblem:
var div = M('div');
div.css({
width: '100px',
padding: '10px',
background: "#333"
})
var a = div.newElement('a');
a.css({
color: 'white'
})
a.html('Exemplo')
a.attrs({
href: "https://jsfiddle.net/",
target: "_blank"
})
var p = div.newElement('p');
p.html('Texto que não deveria ser adicionado ao link')
<script src="https://rawgit.com/samirbraga/libM/master/mlib.js"></script>
<div></div>