How to replace <a> with <span> via DOM

Discussion in 'JavaScript' started by depi, Apr 6, 2007.

  1. #1
    Hi guys.

    By yesterday I'm struggling with the DOM. I would like to create an AJAX based poll where when a user votes it changes the link to a normal text. Everything is working except this change after voting. I don't know how to change <a> to a <span>.

    Here is my HTML code:
    
    <div class="poll">
    <h3>Question?</h3>
    <a href="javascript://" onclick="xajax_hlasuj('1', '0');" id="hlasuj1-0">Answer 1</a>
    <span class="pollbar-full"><span class="pollbar-percent" id="pollbar1-0" style="width: 50%;">50%</span></span>
    
    <a href="javascript://" onclick="xajax_hlasuj('1', '0');" id="hlasuj1-1">Answer 2</a>
    <span class="pollbar-full"><span class="pollbar-percent" id="pollbar1-1" style="width: 50%;">50%</span></span>
    
    <strong>Votes all:</strong> <span id="votesall1">60</span>
    </div>
    
    Code (markup):
    And here is what I would like to get:
    
    <div class="poll">
    <h3>Question?</h3>
    <span>Answer 1</span>
    <span class="pollbar-full"><span class="pollbar-percent" id="pollbar1-0" style="width: 50%;">50%</span></span>
    
    <span>Answer 2</span>
    <span class="pollbar-full"><span class="pollbar-percent" id="pollbar1-1" style="width: 50%;">50%</span></span>
    
    <strong>Votes all:</strong> <span id="votesall1">60</span>
    </div>
    
    Code (markup):
    I had a working version, but it not worked well in IE, so now I have nothing. Could anyone of you please give me an theoretically advice or some of JS code?

    Thanks very much.
     
    depi, Apr 6, 2007 IP
  2. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Just put the <a> tag inside another element, and update the content of that element

    <div id="blabla">
    <a href="javascript://" onclick="xajax_hlasuj('1', '0');" id="hlasuj1-0">Answer 1</a>
    </div>

    and then just update the innerHTML for blabla.
    Why does everyone want to make simple things complicated ?
     
    bibel, Apr 6, 2007 IP
  3. depi

    depi Active Member

    Messages:
    845
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    68
    #3
    To be truly I know this solution, but then I have there some CSS bug issue in IE so this is why I do things so complicated :)
     
    depi, Apr 6, 2007 IP
  4. briansol

    briansol Well-Known Member

    Messages:
    221
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #4
    briansol, Apr 11, 2007 IP
  5. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Another option could be: displaying/hiding the "blabla" DIV using display sytle: display='' and display='none'
     
    ajsa52, Apr 14, 2007 IP