Victor York
Victor York

Reputation: 1681

Find and remove text in div with jquery

Im having trouble trying to find a text in a jquery modal and removing it.

<div id="layer-303" class="layer">
    <div id="boton_cerrar" class="cerrar" onclick="javascript:void(cerrarLayer('layer-303'));">cerrar</div>
        <div class="cnt_sin_pst">
            <div id="id_pst_layer_0" class="pst_contenido">
                <div class="mod mod100">
                    '','canal'=&gt;'null','seccion'=&gt;'null','canal_name'=&gt;'internet2015'); ?&gt;<div class="pill">
                    <div class="contentweb">

The text inside the div mod mod100 is what im trying to find and remove. I have used the following but it removes all the html inside the modal.

$(".layer:contains(''','canal'=&gt;'null','seccion'=&gt;'null','canal_name'=&gt;'internet2015'); ?&gt;')").remove()

The exact text which appears when opening the modal is: '','canal'=>'null','seccion'=>'null','canal_name'=>'internet2015'); ?>

Upvotes: 0

Views: 59

Answers (1)

gavgrif
gavgrif

Reputation: 15499

In order to preserve the remaining content - you want to simply remove that text (assumng it is always that content - the best solution would be to find the reason why its being inserted and remove that cause - but what you can do is simply replace the offending text string without destroying other html content.

var content  = $('.mod.mod100').html();
    
    var str = "'','canal'=&gt;'null','seccion'=&gt;'null','canal_name'=&gt;'internet2015'); ?&gt;";
    
    $('.mod.mod100').html(content.replace(str, ''));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="layer-303" class="layer">
    <div id="boton_cerrar" class="cerrar" onclick="javascript:void(cerrarLayer('layer-303'));">cerrar</div>
         <div class="cnt_sin_pst">
            <div id="id_pst_layer_0" class="pst_contenido">
                <div class="mod mod100">
 '','canal'=&gt;'null','seccion'=&gt;'null','canal_name'=&gt;'internet2015'); ?&gt;<div class="pill">
                    <div class="contentweb">
                    </div>
                  </div> 
                </div>
              </div>
            </div>
          </div> 

Upvotes: 1

Related Questions