tags:

views:

61

answers:

1

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  A: 

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}.

Scott
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.
David Willis
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.
Scott