0
<p>
  This is sample text 
  <span 
    data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;sample text&quot;}" 
    data-sheets-userformat="{&quot;2&quot;:769,&quot;3&quot;:{&quot;1&quot;:0},&quot;11&quot;:3,&quot;12&quot;:0}" 
    data-sheets-note="110/mo">
    sample text
    <a href="#" target="_blank" rel="noopener">
      Sample Text
    </a> 
    Sample Text&nbsp;
  </span>
</p>
<p>
  This is sample text.&nbsp;
</p>
<h2>This is sample text</h2>

The html contains several attributes that starts with 'data-sheets-'. For example: data-sheets-value, data-sheets-userformat, data-sheets-note and many more may be there.

I need to remove all the attributes that starts with 'data-sheets-' along with their values using jQuery from the html. I can't statically consider the presence of only 3 attributes that starts with 'data-sheets-' as there are many more.

removeAttr() of jQuery requires full attribute name. Please guide how can I remove all the attributes from the entire html page that starts with 'data-sheets-'. I mean I need something like removeAttr('data-sheets-*').

Please guide how can I achieve this using jQuery.

Mister Jojo
  • 20,093
  • 6
  • 21
  • 40
Vrajesh Doshi
  • 744
  • 2
  • 8
  • 27
  • 2
    Does this answer your question? [Removing all dynamic 'data attributes' of an Element](https://stackoverflow.com/questions/24059268/removing-all-dynamic-data-attributes-of-an-element) – Ankit Tiwari Oct 08 '21 at 12:49
  • https://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element-with-javascript-jquery – epascarello Oct 08 '21 at 12:51
  • @AnkitTiwari In my scenario, attributes starting with 'data-sheets-' may be available on any html element not necessarily div and also on more than 1 html element through out the page. the solution in the link you shared is not working out for me or may be I have not well understood. Can you please help to get the solution for my exact problem – Vrajesh Doshi Oct 08 '21 at 13:26
  • 1
    *may be on any element* - change `$.each($('div').data(),` to `$("*").each(function() { $.each($(this).data(), ...` – freedomn-m Oct 08 '21 at 13:28

0 Answers0