0

I've got this element that's not precisely defined as a div or anything but just white space popping up inside the html. Can't get to it with jQuery to remove it. Type of element is highlighted in the screenshot. enter image description here

lbennet
  • 1,025
  • 5
  • 13
  • 31
  • 4
    your image is not clear – Neel Apr 02 '14 at 06:18
  • try this - jQuery('.product-container').text() – dikesh Apr 02 '14 at 06:21
  • why remove it with javascript? You can't remove by server side? Some process have add this space. – user3401335 Apr 02 '14 at 06:21
  • The image is fine if you open it up, but it doesn't provide any insight into the source of the element. Maybe you can stop it from ever being created instead of deleting it once it is. – Michael Apr 02 '14 at 06:21
  • 1
    possible duplicate of [How do I select text nodes with jQuery?](http://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery) – Felix Kling Apr 02 '14 at 06:39
  • See here: [How to manipulate text nodes in html](http://stackoverflow.com/questions/7329042/how-to-manipulate-text-nodes-in-html) – Pluto Mar 02 '15 at 20:21

3 Answers3

0

The answer is not simply.

jQuery can map objects with structure. It's very hard to catch just whitespaces as DOM elements and remove them.

I cant suggest 2 alternatives:

  1. Use jQuery to get parent tag, extract innerHTML and user regex to remove "extra whitespaces" between tags:

    $(document).ready(function(){
      var container = $('.product-container');
      container.html(container.html().replace(/>\s+</i, '><'))
    });
    
  2. Use css to clean how looks my content inside that tag as suggests thirtydog here

Hope this help!

Community
  • 1
  • 1
0

Im not expert, but maybe you could use .prev() method.

Something like

$('#main .content').prev();
0

Pure Javascript to select it:

var textNode = document.getElementById("main").getElementsByClassName("filter-navigation")[0].nextSibling;

and remove it:

textNode.parentElement.removeChild(textNode);

jQuery simplifies the selection a bit, but the removal has to be done the same way since jQuery doesn't like removing text nodes:

var textNode = $("#main").find("filter-navigation")[0].nextSibling;
textNode.parentElement.removeChild(textNode);
cazzer
  • 1,524
  • 1
  • 16
  • 26