0

I need to clean span elements out of an HTML include, going by this example. However it just returns the first plain text string in the include and drops everything else (the include has over a dozen href links that I want to preserve).

  $scope.footermenu = function () {
      $http.get('includes/mainmenu.html').success(function(data) {
        var menusrc = data;
        $(menusrc).find('span').remove();
        var nospans = $(menusrc).html();
        return nospans;
      });
    };  
});
Community
  • 1
  • 1
David Smith
  • 89
  • 1
  • 6

1 Answers1

0

I could not get replace() to work here in nearly 4-hours of trying every trick google could find, so I went back to the regex. I had forgotten that angular adds class="ng-scope" to every dom element under its purview (AFAICT), so I needed to stick that in my regex to get it working. Also note "msrc" is being pulled in from the dom, though this did not seem to make a material difference to the particular problem:

  $scope.footermenu = function () {
        var msrc = $('#menu').html();
        var nospans = function() {
          return msrc.replace(/<span class=\"ng-scope\">(.*?)<\/span>/g,'');
        }
        var mcln = $('<div/>').append( nospans() ).html();
        alert(mcln);
    };

A fair bit of clean-up needed and additional modifications to the footer code, but past that hurdle anyway. Thanks to @munsai for that rather crucial tip. It was pointed out elsewhere that msrc !== $(msrc), so this solution bypasses that particular issue (assuming that info is correct).

Community
  • 1
  • 1
David Smith
  • 89
  • 1
  • 6