0

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'); ?>

Victor York
  • 1,621
  • 4
  • 20
  • 55

1 Answers1

1

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> 
gavgrif
  • 15,194
  • 2
  • 25
  • 27
  • what if I have the same text twice in my modal in different divs? It only removes the first one but not the second one. https://jsfiddle.net/u22k3eqj/32/ – Victor York Oct 25 '18 at 11:03
  • @PLATANIUM in that case you need to specify all that divs some how. `$('.mod.mod100').html(content.replace(str, ''));` this code is touches all divs with `class="mod mod100"` Here's example http://jsfiddle.net/smollet92/q2w0zgbv/ – Smollet777 Oct 25 '18 at 11:12