I am trying to show and hide certain buttons based on event click. I am using jQuery and the .data() method to handle this.
Here is my markup (note - I have many repeating divs in the doc with differing ids and I trying to hone in on particular ids for my event click):
<div>
<button id="activate001003" class="jq_activate" data-reference="B1" style="display: inline;" type="button">B1</button>
<button id="deactivate001003" class="jq_deactivate" data-reference="B2" style="display: none;" type="button">B2</button>
<button id="edit001003" class="jq_edit" data-reference="B3" style="display: none;" type="button">B3</button>
</div>
<div>
<button id="activate002007" class="jq_activate" data-reference="B1" style="display: inline;" type="button">B1</button>
<button id="deactivate002007" class="jq_deactivate" data-reference="B2" style="display: none;" type="button">B2</button>
<button id="edit002007" class="jq_edit" data-reference="B3" style="display: none;" type="button">B3</button>
</div>
Here is my jQuery:
$( '.jq_activate' ).click(function() {
$(this).data('reference','B1').css('display', 'none');
$(this).data('reference','B2').css('display', 'inline');
$(this).data('reference','B3').css('display', 'inline');
});
I can't get the buttons to show and hide properly on click event. Any suggestions?
Amendment
I added another group to show that the page has dozens of buttons and I am trying to hone in on only 1 set of buttons.
$(this)all 3 times. I don't think that's what you want, but I can't figure out what you really want..data('reference', 'B2')means? It's not a filter that matchesdata-reference="B2", it means to changedata-referencetoB2(actually it works on an internal jQuery cache, it doesn't update the attribute)..hide()and.show()?