Skip to content

How to remove a tag that without some attribute value #589

Answered by BoDonkey
SettingDust asked this question in Q&A
Discussion options

You must be logged in to vote

You should be able to do this with exclusiveFilter.

sanitizeHtml(
  '<p desired-att="desiredValue">This is the test HTML</p>',
  {
    exclusiveFilter: function(frame) {
      return !frame.attribs.hasOwnProperty('desired-att') || frame.attribs['desired-att'] !== desiredValue;
    }
  }
);

Basically, just write a function that returns true if the section of HTML should be removed. In the code above, I'm returning true if the attribs object doesn't have a key that is equal to the attribute that I want present or if that attribute doesn't have a specific value.
Hope this helps!

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@SettingDust
Comment options

@BoDonkey
Comment options

Answer selected by SettingDust
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants