1

Hi in my css file I create following css:

 #searchoption.root{
  width:100%;
    top:200px;
    z-index:4;
    background-color:black;
  }

  #searchoption.optionfield{
      background-color: #484848;
      height:150px;
      width:100%;
      z-index:3;
}

 #searchoption.dropbar{
        background-color: #656565;
        height:24px;
        width:100%;
        z-index:4;
        border-color:#828282;
        border-style:solid;
        border-width:0px;
        border-bottom: 1px;
        border-top:1px;
    }

and in my js file I create the following:

 var searchoptionrootID = "searchoption.root";
var dropbarID = "searchoption.dropbar";
var innershadowID = "searchoption.innershadow";
var optionfieldID = "searchoption.optionfield";
var outershadowID = "searchoption.outershadow";

var searchoptionroot;
var dropbar;
var innershadow;
var outershadow;
var optionfield;

function initSearchOption(){
    // initialisiert die suchoption leiste
    searchoptionroot = document.createElement("div");
    dropbar = document.createElement("div");
    innershadow = document.createElement("div");
    outershadow = document.createElement("div");
    optionfield = document.createElement("div");

    searchoptionroot.setAttribute("id",searchoptionrootID);

    dropbar.setAttribute("id", dropbarID);


    innershadow.setAttribute("id",innershadowID);

    outershadow.setAttribute("id",outershadowID);

    optionfield.setAttribute("id",optionfieldID);


    searchoptionroot.appendChild(optionfield);
    searchoptionroot.appendChild(innershadow);
    searchoptionroot.appendChild(dropbar);
    searchoptionroot.appendChild(outershadow);

    return searchoptionroot;
}

In the jsp i just return the object and append it to the document:

but it is not working why?

if (searchoption == null ){ 
            searchoption = initSearchOption();

            document.body.appendChild(searchoption);

            alert("height: " + document.getElementById("searchoption.root").style.width);
        }

Does anybody know?

4 Answers 4

2

You should not use the . character in an ID for CSS.

The CSS selector #searchoption.root matches elements with an ID of searchoption and a class of root.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, you can. ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Right. Because clearly I couldn't have commented and voted on the answer that was just plain wrong before seeing the edit that completely changed it.
0

#searchoption.root means "An element with the id searchoption that is a member of the class root.

Your element has the id searchoption.root and isn't a member of any classes.

Your options:

  1. Set the id and class of the element to match the selector
  2. Change the selector to #searchoption\.root
  3. Change the selector and id to use an underscore instead of a period (since underscores don't have special meaning in CSS selectors)

3 Comments

I changed it to an underscore, but its not displayed anyway. What should I do?
If you've changed all the selectors and all the ids, then it should work (assuming the style sheet is linked to the document correctly)
it is, strange... it is only working when I set it up in setAttributes. But I dont want to set it there. I am running it on a jboss, all in a war file, when I set the elements direclty in the jsp it is working ... but not in the js file
0

Try without using dot (.) in your element ID.

searchoption.root will be applyed to an element with css class "root" that is a sub element of control with id="searchoption" which does not seem to exist on your page.

Comments

0

Your code work well if you delete points: http://www.jsfiddle.net/pereskokov/uGA72/1/

Also be aware of using consturction element.style — in Chrome, for example, this construction returns only styles that were set direct in tag or manualy by javascript, but does not return computed styles or matched css rules.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.