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

MONZTAAA
  • 1,591
  • 3
  • 18
  • 52
  • 2
    you can just use `innerHTML` and a simple string [`replace` method](https://stackoverflow.com/questions/5955823/replacing-string-in-innerhtml) – vsync Oct 25 '18 at 10:13
  • Possible duplicate of [How to replace innerHTML of a div using jQuery?](https://stackoverflow.com/questions/1309452/how-to-replace-innerhtml-of-a-div-using-jquery) – vsync Oct 25 '18 at 10:14
  • @vsync that would change everything inside my modal to whatever I replace it with – MONZTAAA Oct 25 '18 at 10:16
  • 2
    `node.innerHTML = node.innerHTML.replace('x','y')` – vsync Oct 25 '18 at 10:21
  • Could you help me out? I cant seem to figure it out: https://jsfiddle.net/u22k3eqj/24/ – MONZTAAA Oct 25 '18 at 10:33
  • @vsync can u check the fiddle i created to solve my issue? – MONZTAAA Oct 25 '18 at 10:43
  • what exactly am I supposed to do in the fiddle? you left no instructions – vsync Oct 25 '18 at 11:48

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
  • 14,151
  • 2
  • 21
  • 24
  • 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/ – MONZTAAA 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