3

I can use javascript to get html tags and divs to appear but I want to put some text in a div.

    this.buildDomModel(this.elements["pans"],
        { tag: "div", className: "panel",
          id: "tabs",
          childs: [
            { tag: "div", id: "page_button",
              className: "box",
              childs: [
                { tag: "div", className: "tab_left" },
                { tag: "div", className: "tab_middle",
                { tag: "div", className: "tab_right" }
              ]},  
]

So how do I add text to this? I want:

<div class="tab_title">Sample text</div>

to appear in my html within the div tag with classname tab_middle.

How do I achieve this?

Also, if I create several of these "tab-titles" with sample text how do I allign them to the centre of the screen.

Thank so much. As you can tell I am a noice at javascript. I do have some basic html knowledge though. Thanks hope someone can help been struggling through books all day

1
  • edited because html code was missing Commented Jul 27, 2010 at 15:33

1 Answer 1

1

To add the text: { tag: "div", className: "tab_title", innerHtml: "Sample text" }, some javascript libraries use just "html" rather than "innerHtml".

@Edit:To center divs to the screen, css needs to be: .tab_title {width: ...; margin: 0 auto;}. You need to set an explicit width to get the left/right auto margin to center it. If you just want the text in the divs centered, then .tab_title {text-align: center}.

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

2 Comments

thanks scott, your first point worked. your second point I should make clear my problem, I have a series on <div>s on a tab bar representing buttons and I want to centre them all. each of the divs has the same className. currently they are all alligned to the left. i followed your advice exactly but it did not move them. Any help greatly appreciated. thanks.
If you want to center all the tabs as a group, then you will need to wrap them all in one div and do the centering on that div, not all the individual divs.

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.