How to add a block of div contents in between two other divs using javascript only?

Hello Universe

I am trying to add a div like below

        <div id="topheader" class="topheader">
            <ul>
                <li>
                    <a href="#" title="Library">Library</a>
                </li>
                <li>
                    <a href="#" title="My Uni">My Uni</a>
                </li>
                <li>
                    <a href="#" title="Staff Intranet">Staff Intranet</a>
                </li>
            </ul>
        </div>

in between two other divs

<div id="w3"> 
.... new div to be here ...
<div id="head"> 

I need to get this done using javascript or motools and not jquery.

Sameer Azazi

You can do it using inject

var headEle = document.id('head');

new Element('div', {
    "class": 'topheader',
    "id": 'topheader',
    html: '<ul><li><a href="#" title="Library">Library</a></li><li><a href="#" title="My Uni">My Uni</a></li><li><a href="#" title="Staff Intranet">Staff Intranet</a></li></ul>'
}).inject(headEle, 'before');

Here is a working JS FIDDLE

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I set the div to the height of two other divs with javascript while using bootstrap

From Dev

How to select only one DIV from multiple divs using javascript

From Dev

How to show only the div with id while hiding other divs using CSS only

From Dev

Div in between two divs

From Dev

how to add vertical line between two divs

From Dev

How to add space between two divs in HTML?

From Dev

How can I add a line break between my inline-block javascript divs?

From Dev

How can I add a line break between my inline-block javascript divs?

From Dev

How to dynamically add a div in between Divs

From Dev

Squeeze a div between two other divs when window resizes

From Dev

How to add divs with some classess to another div (inside each other) in html / javascript

From Dev

How to maneuver between two divs using CSS?

From Dev

How to populate a JavaScript array with only the divs that have display:block?

From Dev

How to position a div into the gap created by two other divs

From Dev

How to make two divs side by side using inline-block?

From Dev

Center div between two divs

From Dev

Center div between two divs

From Dev

How do I make a container div only overflow horizontally without using "display:inline-block" for its inner divs?

From Dev

How to add a class to one div but remove from other divs?

From Dev

How to add a class to one div but remove from other divs?

From Dev

Using JavaScript to swap between two unique DIVS using display

From Dev

How to make a div's width stretch between two divs

From Dev

How to center a div sandwiched between two absolute divs?

From Dev

How to add spacing between two rows of multiple divs each

From Dev

How to add spacing between two rows of multiple divs each

From Dev

Center an Inline-block div in between two floated divs inside a footer

From Dev

How to add div between two classes

From Dev

Switching between two div elements using Javascript

From Dev

Switching between two div elements using Javascript

Related Related

  1. 1

    How can I set the div to the height of two other divs with javascript while using bootstrap

  2. 2

    How to select only one DIV from multiple divs using javascript

  3. 3

    How to show only the div with id while hiding other divs using CSS only

  4. 4

    Div in between two divs

  5. 5

    how to add vertical line between two divs

  6. 6

    How to add space between two divs in HTML?

  7. 7

    How can I add a line break between my inline-block javascript divs?

  8. 8

    How can I add a line break between my inline-block javascript divs?

  9. 9

    How to dynamically add a div in between Divs

  10. 10

    Squeeze a div between two other divs when window resizes

  11. 11

    How to add divs with some classess to another div (inside each other) in html / javascript

  12. 12

    How to maneuver between two divs using CSS?

  13. 13

    How to populate a JavaScript array with only the divs that have display:block?

  14. 14

    How to position a div into the gap created by two other divs

  15. 15

    How to make two divs side by side using inline-block?

  16. 16

    Center div between two divs

  17. 17

    Center div between two divs

  18. 18

    How do I make a container div only overflow horizontally without using "display:inline-block" for its inner divs?

  19. 19

    How to add a class to one div but remove from other divs?

  20. 20

    How to add a class to one div but remove from other divs?

  21. 21

    Using JavaScript to swap between two unique DIVS using display

  22. 22

    How to make a div's width stretch between two divs

  23. 23

    How to center a div sandwiched between two absolute divs?

  24. 24

    How to add spacing between two rows of multiple divs each

  25. 25

    How to add spacing between two rows of multiple divs each

  26. 26

    Center an Inline-block div in between two floated divs inside a footer

  27. 27

    How to add div between two classes

  28. 28

    Switching between two div elements using Javascript

  29. 29

    Switching between two div elements using Javascript

HotTag

Archive