How to target the parent div from child div?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.