Change text within a dynamically generated span element without destroying the nested elements

0

My need at first seems basic, but I can not find a way to change the text inside a tag <span> that is generated dynamically.

Below is the excerpt from the DOM where I have the following excerpt: <span>Novo Teste</span> . I need to simply change the text contained within the tag, but without destroying the nested elements.

<li id="0"><span>Novo Teste</span><span class="acoes"> <a href="#" type="reset" class="btn btn-success edit-item" style="position: relative; top: -1px;"> <span class="entypo-pencil"> </span>&nbsp;&nbsp;Editar </a>
    <a id="$('#destination-service-dropdown option:selected').text()" href="#" type="reset" class="btn btn-danger del-item" style="position: relative; top: -1px;"> <span class="entypo-cancel-squared"></span>&nbsp;&nbsp;Cancelar</a>
    </span>
</li>

One unsuccessful attempt was this:

$("#"+idOfListItems+"").next().text($('#destination-service-dropdown option:selected').text());
    
asked by anonymous 03.09.2015 / 22:10

1 answer

1

I would solve it like this:

var contSpan = $('li#'+idOfListItems).find('span');
$(contSpan[0]).html($('#destination-service-dropdown option:selected').text());

I tested it here and it worked.

    
04.09.2015 / 04:34