SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reordering DIV's using JS?

    Hi guys, bit of a javascript newbie

    I am trying to work out how to do something, what I am trying to do is dynamically reorder DIV's if the user clicks a button within the DIV. Not really sure on the best method or approach to this. Does that make sense????

    I.e.

    PHP Code:

    <div id="div01">
         <
    ul>
              <
    li><a href="">Move up</a></li>
              <
    li><a href="">Move down</a></li>
         </
    ul>
    </
    div>

    <
    div id="div02">
         <
    ul>
              <
    li><a href="">Move up</a></li>
              <
    li><a href="">Move down</a></li>
         </
    ul>
    </
    div>

    <
    div id="div03">
         <
    ul>
              <
    li><a href="">Move up</a></li>
              <
    li><a href="">Move down</a></li>
         </
    ul>
    </
    div
    So if the user clicks the up link in Div 3, it then moves it to position 2.

    Cheers
    Si

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before I start, does it matter that the next time the user visits the page or when he hits reload, the divs go back to their original order?

    If so, you need to use some server-side scripting.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser View Post
    Before I start, does it matter that the next time the user visits the page or when he hits reload, the divs go back to their original order?

    If so, you need to use some server-side scripting.
    Hello mate,

    Thanks for the reply. No it dosn't matter as a server side script will store the order of the DIV's

    Thanks
    Si

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this using the DOM. Have those divs inside a container and use the insertBefore method on the parent of those divs to move the children around.

  5. #5
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anybody have any examples or pointers

    Si


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •