help changing the text of a span within a child div

Pertanyaan help changing the text of a span within a child div

  • 24 April 2012 20:50
     
      Memiliki Kode

    Hello,

    I have a span within a child diva nd I want to change the text:

    div class="ms-form" id="_firstName_val">
      <div>
        <span>Bill</span>
      </div>
    </div>
    div class="ms-form" id="_lastName_val">
      <div>
        <span>Jones</span>
      </div>
    </div>

    I have been trying to change it like this:

    $('[id$=_lastName_Value]').text(updateValues.LastName);

    I assume I am doing it wrong and I guess that it is the second div that is giving me an issue. Can you please help with this?

    Thanks

Semua Balasan

  • 13 Mei 2012 2:48
     
     

    Hi, 

    If you want to change only the second span, you can assign it an id and do : document.getElementById("id").innerText = LastName

    Best regards

  • 30 Mei 2012 6:37
     
      Memiliki Kode

    if you know that there will be only two spans and these are static, then i will suggest you to name them and then you can find there value easily.

    div class="ms-form" id="_firstName_val">
      <div>
        <span id="span1">Bill</span>
      </div>
    </div>
    div class="ms-form" id="_lastName_val">
      <div>
        <span id="span1">Jones</span>
      </div>
    </div>

    here i added some names to spans

    $('#span1).text("some new text");
    $('#span2).text("some other text");

  • 07 Juni 2012 17:29
     
     

    Hi smithsf22,

    Can you tell us whether the answers that were given it helped you solve your problem?


    « To create a market we have to invent a problem and then find its solution »

  • 12 Juni 2012 13:37
    Moderator
     
      Memiliki Kode

    You need to direct to the right target control to operate on, here it should be the span in the div which has the id "_lastName_Value".
    What you need is:

    $('#_lastName_Value span').text(updateValues.LastName);

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us