Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Sanitize textarea content by removing all elements apart from tags with jQuery

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #192563
    richerimage
    Participant

    I’d like to see if there is a way to remove all the surplus html apart from the element (and it’s content) that comes with a typical optin form embed code (Mailchimp, Aweber, ect)

    My goal is to have a user paste in the code as provided by the supplier into a textarea and then have it sanitized by clicking a button so they’re just left with the element and it’s content.

    Here’s is a pen of what I have so far. I have no idea of how close/far away I am from any success (or indeed if this is possible at all)

    Any help is, as ever, very much appreciated :)

    Thanks

    Richard

    
    $( '#tidy' ).click(function() {
      var formContent = jQuery('textarea').val();
      $(formContent).not('form').remove();
      alert(formContent);
    });
    
    
    
Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.