Problem with dynamic element creation

0

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>

The new child, which by code should be added to the same element, is added to the child. In case it is div > a > p , which should be div > a, p .

The strange thing is that if I do not pass the element I want to add to a div = M('div') variable and instead use M('div').newElement('p') , it works .

I do not know what's causing this.

The code for the newElement() function:

newElement: function(element){
  var _newElement;
  each(self.myArg, function(el, i) {
    _newElement = document.createElement(element)
    el.appendChild(_newElement);
  })
  return M(_newElement)
},

Thanks in advance.

    
asked by anonymous 14.08.2016 / 22:36

0 answers