How do I insert an Element after another Element using Mootools?
-
For example, if I have the following piece of HTML: <div id="myParent"> <div id="myFirstElement" /> </div> I want the result to look like the following: <div id="myParent"> <div id="myFirstElement" /> <div id="mySecondElement" /> </div> I know I could right some straight JavaScript to do this, such as: _insertAfter: function (newElement, targetElement) { //target is what you want it to go after. Look for this elements parent. var parent = targetElement.parentNode; //if the parents lastchild is the targetElement... if (parent.lastchild == targetElement) { //add the newElement after the target element. parent.appendChild(newElement); } else { // else the target has siblings, insert the new element between the target and it's next sibling. parent.insertBefore(newElement, targetElement.nextSibling); } } But I want to know how to do inside Mootools.
-
Answer:
new Element('div', {id: 'mySecondElement'}).inject('myFirstElement', 'after'); You can find documentation on : http://mootools.net/docs/core/Element/Element#Element
Sylvain Robez-Masson at Quora Visit the source
Related Q & A:
- How can I insert posted data into the database?Best solution by Stack Overflow
- How can I remove an element in a repeated list?Best solution by Stack Overflow
- How can I insert image in my Yahoo profile?Best solution by Yahoo! Answers
- How do I insert my photo in my messenger?Best solution by Yahoo! Answers
- How can I insert HTML into my Yahoo Group description?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.