Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  135] [ 2]  / answers: 1 / hits: 18981  / 14 Years ago, wed, may 5, 2010, 12:00:00

I want to be able to append divs to my page such that they are appended after a div of a certain class and before teh divs that follow it i.e:


<div class="header">Header DIV</div>
<!-- Want to add using javascript some HTML right here-->
<div class="one-basic-div">...</div>
<div class="one-basic-div">...</div>
<div class="one-basic-div">...</div>
<div class="one-basic-div">...</div>

It is basically raw html I wish to add. How can I do it?


More From » html

 Answers
3

Use the Element.insert method:





document.observe(dom:loaded, function() {
$$(.header).first().insert({ after: <p>Some html</p> });
});

<script src=https://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js></script>

<div class=header>Header div</div>
<div class=one-basic-div>Other div</div>




[#96873] Sunday, May 2, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;