title: Removing data attributes from HTML using jQuery
body: <p>Can't seem to get this one to work...</p>
  
  <p>I have a page that hides certain links. When the DOM is loaded, I'm using jQuery to toggle some of those elements.  This is driven by using a data attribute like so:</p>
  
  <pre><code>&lt;div class="d_btn" data-usr='48'&gt;
    &lt;div class="hidden_button"&gt;
  </code></pre>
  
  <p>Then, I have the code:</p>
  
  <pre><code>  $.each($(".d_btn"), function() {
       var btn = $(this).data('usr');
     if ( btn == '48' ){      
       $(this).children('.hidden_button').toggle();
     }
  </code></pre>
  
  <p>The above all works as planned.  The problem is that I am trying to remove the data-usr from the class .d_btn once the if statement is evaluated.  I've tried the following and nothing works (i.e., after the page is loaded, the source still shows the data-usr attribute:</p>
  
  <pre><code>$(this).removeAttr("data-usr");
  
  $(this).removeData("usr");
  </code></pre>
  
  <p>I've been working on this for a couple of hours now and...nothing!  Help is greatly appreciated!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've tried the great suggestions of setting the data attribute to an empty string but I'm still not getting the desired result.</p>
  
  <p>To explain a little further, The reason I'm trying to remove the attribute is so when an ajax response adds another item to the page, the previously added items would already have the button either shown or hidden.  Upon AJAX response, I'm calling the same function once the DOM is loaded.</p>
  
  <p>Currently, when something is added via AJAX, it toggles all the buttons (showing the ones that were hidden and vice versa.)  Ugh...</p>
  
  <p>I'm also fully willing to try alternatives to my approach.  Thanks!</p>
  
  <p><em><strong>UPDATE</em></strong></p>
  
  <p>Well, the light bulb just flashed and I am able to do what I want to do by just using .show() instead of .toggle() </p>
  
  <p>Anyway, I'd still like to find an answer to this question because the page will be potentially checking hundreds of items whenever something is added - this seems horribly inefficient (even for a computer, hahaha.) </p>