1

Basically what I have is this:

<body>
 <div class="class1">
 </div>
 <div class="class2">
 </div>
 <div class="class3">
 </div>
...
</body>

I have no idea why the site creator used classes instead of IDs (they're unique), but it doesn't really matter as I'm writing a GM script and so getElementsByClassName('')[0] effectively does the same thing.

How can I insert an element between the first and second div?

2 Answers 2

2

Create your own insertAfter function

Sign up to request clarification or add additional context in comments.

2 Comments

no problem :) Take a look at my answer for some tips on writing your own cross-browser DOM traversal functions - stackoverflow.com/questions/920478/…
I ended up using insertBefore instead... seemed easier. Thanks for the link!
1

you can use JQuery it very simple

$(".class1").after( document.createTextNode("Hello") );

2 Comments

Using jQuery in a greasemonkey script is somewhat over the top, don't you think? ;)
No I did not think so, I just suggest you a option to your problem. Out of curiosity:It definitely does not deserves a -1 score.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.