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 4336882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:52:04+00:00 2026-05-21T10:52:04+00:00

i have a div <div id=mainDiv onclick=devide(this.id, event); style=z-index:1;position:relative; width:400px; height:400px; border:1px red solid;></div>

  • 0

i have a div

<div id="mainDiv" onclick="devide(this.id, event);" style="z-index:1;position:relative; width:400px; height:400px; border:1px red solid;"></div>

on its click i append to more divs to it and want the same thing to happen to them, means on there click 2 more divs shud b added to them

on click on mainDiv
mainDiv
-mainDiv0
-mainDiv1

on click on mainDiv0
mainDiv
-mainDiv0
-mainDiv00
-mainDiv01
-mainDiv1

i guess i was able to clear the things

i used following js

function devide(id, evt){
    alert(id);
    var divElement = document.getElementById(id);
    if(typeof(divElement) != "undefined" && divElement!=null){
        captureMousePosition(evt);
        if(splitVertical==1)
            verticalSplit(divElement);
        else
            horizontalSplit(divElement);
    }
}

function verticalSplit(divElement){
    divElement.style.border = "0px red dashed";
//  divElement.removeAttribute("onclick");
    var width = ((divElement.offsetWidth-(xMousePos-LEFT_MARGIN))/divElement.offsetWidth)*100;
    var newDiv1 = document.createElement("div");
    newDiv1.setAttribute("id", divElement.id+"0");
//  newDiv1.onclick = "devide('"+divElement.id+"0', event);";
    newDiv1.style.width = (100-width)+"%";
    newDiv1.style.height = "100%";
    newDiv1.style.float = "left";
    newDiv1.style.border = "1px red dashed";
    newDiv1.style.zIndex = divElement.style.zIndex+1;
    var newDiv2 = document.createElement("div");
    newDiv2.setAttribute("id", divElement.id+"1");
    newDiv2.style.width = width+"%";
    newDiv2.style.height = "100%";
    newDiv2.style.float = "left";
    newDiv2.style.border = "1px red dashed";
    newDiv2.style.zIndex = divElement.style.zIndex+1;
    divElement.appendChild(newDiv1);
    divElement.appendChild(newDiv2);
    newDiv1.addEventListener("click",devide(divElement.id+"0", event),true);
    newDiv2.addEventListener("click",devide(divElement.id+"1", event),true);
}

but this is recursively calling devide function for the first encountered element say mainDiv0,mainDiv00,mainDiv000…. and so on

please help me with this

  • 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-05-21T10:52:06+00:00Added an answer on May 21, 2026 at 10:52 am

    The situation you are describing is called event bubbling.

    The W3C model says you can call .stopPropagation() on the event. IE might need window.event.cancelBubble

    To do unobtrusive javascript with your code try:

    HTML

    <div id="mainDiv"></div>
    

    JS

    function devide(evt){
        var divElement = document.getElementById(this.id);// this.id !
        if(typeof(divElement) != "undefined" && divElement!=null){
            captureMousePosition(evt);
            if(splitVertical==1)
                verticalSplit(divElement);
            else
                horizontalSplit(divElement);
        }
    }
    
    document.getElementById('mainDiv').onclick=devide; // notice it's just the function name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent div with a fixed position and inside of that div
On my page I have main div, which is generated by a plugin from
In my web page a have a div where I put some tabs. The
I'm currently trying to have an iframe fit the size of my screen, and
I have read many articles about vertical centering but I’m afraid not many of
I have read all your responses and come to the conclusion that is a
I have another CSS problem. A layout that escapes me. I could, I suppose,
I'm attempting the surprisingly difficult task of finding out which element was clicked. I
I want to do the kind of menu, where when you hover the item,
Consider the following code (it is based on a default EMPTY MVC3 project created

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.