开发者

How to add html after a certain div using Prototype JS?

开发者 https://www.devze.com 2022-12-29 10:52 出处:网络
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:

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="开发者_StackOverflowone-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?


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>


Use insert:

$$('#header').insert({ 'after' : theHTML });

That should insert it as a sibling after the div with id header.

There are some helpful examples here, the documentation seems to be lacking, somewhat.

0

精彩评论

暂无评论...
验证码 换一张
取 消