1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Span alignment with Div using JavaScript

Discussion in 'JavaScript' started by asifakhtar, Oct 5, 2010.

  1. #1
    Hi,
    I have a div(MedicalBriefsDocumentsTable) with the align attribute set to "center”. I have a span(currentClaimantName) with no align attribute.

    How can I align the span with the div using JavaScript because the div will expand or shrink based on contents. I want to know where the div position starts and assign that to span using JavaScript.

    Please make sure that the div and the span are empty when the page loads. The div and the span will fill when user selects a row from another table.

    My Html is:
    
    	<table align="center">		
    		    <tr>
    		        <td>
    		            <span id="currentClaimantName"></span>
    		        </td>
    		    </tr>
    		    <tr>
    		        <td>
    		            <div id="MedicalBriefsDocumentsTable" align="center"></div>
    		        </td>
    		    </tr>
    		</table>
    Code (markup):
    Thanks
     
    asifakhtar, Oct 5, 2010 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I'm not exactly sure what you mean. Align the span where (in relation to the div)?
    
    	<table  style="text-align: center;">		
    		    <tr>
    		        <td>
    		            <span id="currentClaimantName"></span>
    		        </td>
    		    </tr>
    		    <tr>
    		        <td>
    		            <div id="MedicalBriefsDocumentsTable"></div>
    		        </td>
    		    </tr>
    		</table>
    
    Code (markup):
     
    camjohnson95, Oct 6, 2010 IP
  3. asifakhtar

    asifakhtar Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #3
    Align the span in relation to the div.
     
    asifakhtar, Oct 6, 2010 IP
  4. bigrollerdave

    bigrollerdave Well-Known Member

    Messages:
    2,112
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Someone correct me if I'm wrong but I'm not sure there is a way to get the location of a div that is aligned to center. You can get the location of the div is it's position was set to absolute.

    Just a question: why not just left align the cells? Then they would both be aligned.
     
    bigrollerdave, Oct 6, 2010 IP