Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9287917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:47:41+00:00 2026-06-18T19:47:41+00:00

So I have created an draggable div, that I want to be on top

  • 0

So I have created an draggable div, that I want to be on top the other divs when dragging around it on the content.

I have tried style.zindex=1 but it don’t seem to solve the problem, If I do it with Jquery there is no problem, but I want to solve it by JavaScript.

Any tips ?

This is what i have come up with.

  function changeClass() {
            var diceClass = document.getElementsByClassName("window");
            for(var i = 0; i<diceClass.length; i++){
                var z = 10;
                diceClass[i].style.zIndex=z++;
            console.log(diceClass)
            } 
        } 
        changeClass()

And my Css

.window
{

    width               : 342px;
    height              : 182px;
    top                 : 0px;
    left                : 0px;
    position            : absolute;
    background          : url(window.png) no-repeat;

    -webkit-user-select: none;
   -moz-user-select: none;
   -ms-user-select: none;
   -khtml-user-select: none;
   user-select: none;
   cursor: default;

    }

I created an jsFiddle.
The code is on row 31 – 42

http://jsfiddle.net/dymond/tQdFZ/1/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:47:42+00:00Added an answer on June 18, 2026 at 7:47 pm

    Here’s a fixed jsfiddle.

    You were adjusting the z indexes with a ‘click’ event. Click events don’t fire until it receives both a mousedown and mouseup event. This means the z indexes weren’t actually being applied until after you stopped dragging.

    Since you’re already handling the mousedown event with startDrag, you can use a closure variable to keep track of the current highest z index and just increment it as you go.

    var draggable = document.getElementsByClassName('draggable'),
        draggableCount = draggable.length,
        i, currZ = 1;
    
    
    function startDrag(evt) {
    
        var diffX = evt.clientX - this.offsetLeft,
            diffY = evt.clientY - this.offsetTop,
            that = this;
    
        this.style.zIndex = currZ++;
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image inside a div. I want that image to be draggable
I have created some JQuery that will expand a div 'popup' on hover and
I have created a set of divs of different size that all reside within
I have a div, which has jQuery UI Draggable applied. What I want to
I have created an input that creates divs to use as menu items. These
I have a form created in Windows Forms which is draggable wherever I click.
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a function that shows/hides different messages according to a combination of
I have a div with draggable and resizable functionality of jQuery UI . I
I tried searching but i didnt find anything helpful :( I have a draggable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.