Each does not work

1

I want to give a replace in the tag <a> by <span> .

I tried to do this, but it does not work:

$(document).ready(function() {
  $('#lista-noticias .box-noticia .conteudo-noticia').each(function() { 
    alert("teste");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><divid="lista-noticias">       
  <div class="box-noticia">
    <div class="conteudo-noticia">
      <a href="qualquer.coisa1.html">
    </div>
  </div>
  <div class="box-noticia">
    <div class="conteudo-noticia">
      <a href="qualquer.coisa2.html">
    </div>
  </div>
  <div class="box-noticia">
    <div class="conteudo-noticia">
      <a href="qualquer.coisa3.html">
    </div>
  </div>
  <div class="box-noticia">
    <div class="conteudo-noticia">
      <a href="qualquer.coisa4.html">
    </div>
  </div>
</div>
    
asked by anonymous 10.05.2016 / 16:35

3 answers

2

Assuming your <a> tags are closed with the corresponding </a> and have some text, then you can use .replaceWith() " of jQuery and do so:

$('#lista-noticias .box-noticia .conteudo-noticia a').replaceWith(function() {
    return $('<span/>', {html: this.innerHTML});
});

jsFiddle: link

This method overrides all selector elements with the return of the iterator function.

    
10.05.2016 / 16:53
0

The code works the way it is written (see below):

link

Make sure you have no errors in your Browser Console, particularly that jQuery is being included correctly.

    
10.05.2016 / 16:51
0
   $('#lista-noticias .box-noticia .conteudo-noticia').each(function() { 
          $(this).find("a").replaceWith("<span>abcd</span>");
        });

Follow: link

    
10.05.2016 / 16:52