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

  • SEARCH
  • Home
  • 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 6772003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:29:55+00:00 2026-05-26T15:29:55+00:00

I am trying to create a div element which shows some text as popup.

  • 0

I am trying to create a div element which shows some text as popup. But the problem is when i create the element using javascript, the div already contains the default style which is defined in document style sheet or external css. Like for example:

popup = document.createElement("div");
popup.setAttribute("id","myElement");
popup.style.left = "100px";
popup.style.top = "100px";
popup.style.width = "100px";
popup.style.height = "100px";
document.body.appendChild(popup);

and now when it shows up, it already has colors, borders etc because in css there is this div style which is being applied on this element. I want it to not inherit anything which is defined for the document itself, how can i do that, or may be overwrite the original style??

  • 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-26T15:29:55+00:00Added an answer on May 26, 2026 at 3:29 pm

    So I made something like this. It may not be ideal solution but it atleast does what i wanted:

    function displayMenu(){ 
        var popup;
    
        //see if there is already default style defined in the document
        var styleSheets = document.styleSheets;
        var size = styleSheets.length;
        var cssRules = new Array();
        var rules = "";
        var css, len, st, sp;
    
        for (i=0;i<size;i++){
            cssRules[i] = styleSheets[i].rules || styleSheets[i].cssRules;
            for (j=0;j<cssRules[i].length;j++){
                if(cssRules[i][j].cssText.search(/div/i) != -1){
                    css = cssRules[i][j].cssText;
                    css = css.substr(((css.search("{"))+1),((css.search("}"))-(((css.search("{"))+1))));
    
                    if((css.search("{") == -1) && (css.search("}") == -1)) {
                        //no of css-properties in this specific rule
                        len = css.split(";").length - 1;
    
                        for (k=0;k<len;k++){
                            st = css.search(";") + 1;
                            rules += css.substr(0,(css.substr(0,st).search(":")+1)) + "0\n";
                            css = css.substr(st);                       
                        }
    
                    } else {} //ignore this rule
                }
            }
        }
    
        var reset = '.myStyle { '+ rules +' }\n';
    
        //now create a css Class which overwrite default document properties for this <div> element
        var myStyle = document.createElement('style');
        myStyle.type = 'text/css';
        //TODO: should be replaced with style from arguments
        myStyle.innerHTML = reset;
        document.getElementsByTagName('head')[0].appendChild(myStyle);
    
        //start creating the popup menu:
        var popup;
        popup = document.createElement("div");
        popup.setAttribute("id","guide_popup");
        popup.setAttribute("class","myStyle");
    
        //now define own style rules: (All basic properties need to be defined as there is none by defualt now)
        popup.style.top = top;
        popup.style.left = left;
        popup.style.width = width;
        popup.style.height = height;
        popup.style.zIndex = index;
    
        //TODO: should be replaced with str in aruguments
        var popup_text = document.createTextNode("This is my sample text");
        popup.appendChild(popup_text);
    
        //finally process the DOM
        document.body.appendChild(popup);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using fadeIn() on div that contains elements which positions are
Hihi, I am trying to create a slide down menu using DIV, but hit
I'm trying to create a small html fragment (a div element) consisted of three
I'm trying to create a standardized show/hide element system, like so: <div class=opener popup_1>Click
I'm trying to create a new div each time a text field contained in
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create a buttonbar using simple <div> and change its opacity
I'm trying to create a function that shows a modal dialog which when called
Using Prototype 1.6's new Element(...) I am trying to create a <table> element with
I'm trying to create a custom overlay that basically just contains a HTML element

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.