Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   Adding div elements with JavaScript (http://www.programmingforums.org/showthread.php?t=12659)

Wizard1988 Feb 24th, 2007 11:00 PM

Adding div elements with JavaScript
 
I have a page which lists information on courses Link. I am trying to create a back to top link after the information for each course.

Each section describing a course looks like this

:


<div class="article">
    <div class="courseTitle">SCI202    CHEMISTRY 1.0 Cr.<a name="chemistry" id="chemistry"></a></div>
    <div class="courseCategory">Prereq:</div>
    <div class="content">Having passed Integrated Physics and Algebra 1 or Algebra A-B.</div>
<div class="courseCategory">Description:</div>
    <div class="content">
        <p>This course is designed for sophomores who have successfully completed Integrated Physics and Algebra 1 or Algebra A-B.  The subject matter includes the study of the following topics: scientific methods, matter, energy, atoms (behavior and interactions), periodic table, gases, liquids, solids and stoichiometry.  This course is designed to give the student an overview of the basic concepts of chemistry, including how chemistry relates to biology, physics, and earth science.  Students will use various forms of technology to collect, analyze, and report data.</p><p><strong>This course is required and is a prerequisite for biology.</strong></p>

</div>

</div>

How would I go about adding a .backUp element after the last content section within the article?

Any hints or tips are welcome.

Arevos Feb 25th, 2007 6:38 AM

Place something like:
:

  1. <a name="top"/>

At the top of the page, and:
:

  1. <a href="#top">Back to top</a>

At the bottom.

Wizard1988 Feb 25th, 2007 8:38 AM

I know I can do that. However I am looking for a way to automatically add that link after every section describing a class. I hope this clears things up.

Arevos Feb 25th, 2007 10:53 AM

Oh, I see. I'd recommend first getting Prototype, which is a widely used javascript library that makes tasks like these so much easier. And then maybe something like:
:

  1. document.getElementsByClassName("article").each(function(article) {
  2.     new Insersion.Bottom(article,
  3.         '<div class="content"><a href="#top">Return to top</a></div>')
  4. }


Wizard1988 Feb 25th, 2007 11:05 AM

I actually figured it out, but it was much messier than what you did. I think I will check out Prototype.

Thanks.


All times are GMT -5. The time now is 8:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC