0

I have a document that I can't edit in PHP looking like this:

<div class="car-search-field-div">
  <label class="simple_hide">Türen</label>
     <div class="myClear"></div>

     doors_count

     <input id="car-search-form-field-doors_count" name="search[doors_count]" type="text" value="" placeholder="Anzahl Türen ab">
 </div>

Now I am trying to remove the string "doors_count" via jQuery but can't adress it properly. When I try something like:

$('.car-search-field-div').remove('iventory_number', '');

The placeholder of the input field gets removed, but the string "doors_number" still is there. I also thought of using the xpath of the string, but that doesn't work either.

Is there a way to adress / remove a string that has no element wrapped around it? Thank you very much in advance!

  • `doors_count` has element `
    ` as wrapper. To clear text use `$('.car-search-field-div').text('')`, to clear html too use `$('.car-search-field-div').html('')`
    – Justinas Mar 15 '22 at 14:06
  • Use the [DOM API](//developer.mozilla.org/docs/Web/API/Document_Object_Model) directly. Here, for example: `document.querySelectorAll("input[name^='search']").forEach(({ previousSibling }) => previousSibling.remove())`. – Sebastian Simon Mar 15 '22 at 14:06

2 Answers2

0

you can remove inside all text inside .car-search-field-div

$('.car-search-field-div').contents().filter(function () {
     return this.nodeType === 3; 
}).remove();

more detail enter link description here

demo

errorau
  • 2,121
  • 1
  • 14
  • 38
0

You need DOM access

document.querySelector(".car-search-field-div").childNodes.forEach(node => {
  if (node.nodeType === 3 && node.textContent.trim() === "doors_count") node.remove()
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="car-search-field-div">
  <label class="simple_hide">Türen</label>
  <div class="myClear"></div>
  doors_count
  <input id="car-search-form-field-doors_count" name="search[doors_count]" type="text" value="" placeholder="Anzahl Türen ab">
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236