Reputation: 32693
does mootools have equivalent of jQuery's before
?
Or if not, how can I do similar functionality in mootools?
For example, I got result from ajax and I want to insert HTML-code of result before some element.
<div class="elements">
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
</div class="loader"></div>
</div>
I want to insert some HTML code (which is string) before .loader
.
I can't use JSON, or HTML like object in this issue.
I have function which inserts HTML into div:
function appendHTML(elem, html){
if ($type(html) != 'string') return false;
var temp = new Element('div');
temp.set('html', html);
elem.adopt(temp.childNodes);
return this;
}
But I want insert HTML code before div, not into. Thanks!
Upvotes: 1
Views: 646
Reputation: 26134
When you inject your element into the DOM, you can pass in a second argument that says where the element should go. The default is bottom
.
new Element('div', {
"class": 'className',
html: 'Some html'
}).inject(existingEl, 'before');
Upvotes: 6