Replace not a function

Replace not a function

Hey everyone, 

I'm trying to replace/trim out some unwanted text from an ajax call. I've tried using .replace, .trim and .slice and keep getting the same error that none of these are functions. My impression is that this error only happens when I try to target numerical values and not string elements. 

  1. $(function displayGroupItems() {
  2. $('.group-submit').click(function(event) {
  3. $.ajax({
  4. url:'ldap/groups',
  5. method: 'GET',
  6. dataType: 'json',
  7. success: function(data) {
  8. $(this).replace("/cn/g", " ");
  9. $.each(data.groups, function(i, dn) {
  10. output = '<li class="dn-wrapper">' +'<span class="dn-class">'+ dn.dn +'</span>' + '</li>';
  11. $(output).appendTo('#groups-list');
  12. });
  13. }
  14. })
  15. });

  16. });
  Here are some ways I've tried this:
  1. $(output).appendTo('#groups-list').replace('/cn/g',' ');

  1. output = '<li class="dn-wrapper">' +'<span class="dn-class">'+ dn.dn +'</span>' + '</li>';
  2. $(this).replace("/cn/g", "2")
  3. $(output).appendTo('#groups-list');

  1. var str = $(this).replace("/cn/g", "2")
  2. output = '<li class="dn-wrapper">' +'<span class="dn-class">'+ dn.dn +'</span>' + '</li>';
  3. $(output).appendTo('#groups-list');

The ajax returns values such as cn=group1, ou=example, etc.. I would like everything except Group1 to be removed upon success.

Let me know if I'm on the right track if I'm missing something obvious.

Thanks!