remove text within the small without casting the "a" tag with jquery

1

I have the following code, and I would like to remove only the text 'Configuration options:' without changing the 'a' tag with jquery, can anyone help me?

<small>

Opções de configuração: 

<a href="javascript:void(0);" onclick="teste" class="hiperlink" alt="">Alterar
</a>

</small>
    
asked by anonymous 06.12.2017 / 14:53

4 answers

1

You can get text inside elements with nodeType == 3 :

$('small').contents().filter(function(){
    return this.nodeType == 3;
}).remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><small>Opçõesdeconfiguração:<ahref="javascript:void(0);" onclick="teste" class="hiperlink" alt="">Alterar
</a>

</small>
    
06.12.2017 / 15:07
1

I created a button that when clicked will store link in a variable (selecting by its class hyperlink ) and then clean the contents of the <small> tag with the empty () and then add the variable link to its contents using the append () .

$("#Remover").on("click", function(){
  var link = $(".hiperlink");
  $("small").empty().append(link);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><small>Opçõesdeconfiguração:<ahref="javascript:void(0);" onclick="teste" class="hiperlink" alt="">
    Alterar
  </a>
</small>

<div>
  <button id="Remover">
    Clique para remover o texto
  </button>
</div>
    
06.12.2017 / 15:09
0

You can change the html in this way

$("#tag-small").html($("#tag-small a"))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><smallid="tag-small">

Opções de configuração: 

<a href="javascript:void(0);" onclick="teste" class="hiperlink" alt="">Alterar
</a>

</small>
    
06.12.2017 / 15:07
0

One possible solution is to change your html to

$("small > span").text("");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><small><span>Opçõesdeconfiguração:</span><ahref="javascript:void(0);" onclick="teste" class="hiperlink" alt="">
    Alterar
  </a>

</small>
    
06.12.2017 / 15:12