There is a simple illustration
<button id="tri" style='display: block;'>click here</button>
<div id="container" style='display: none;' >
Identified by id
$('#tri').on('click', function(){
var e = document.getElementById('container');
var b = document.getElementById('tri');
if(e.style.display == 'none')
$("#container").slideDown();
b.style.display = 'none';
})
We need to replicate this for another button that identifies only by class
and data-id
<div class="section_view" data-id="13" style='display: none; ></div>
My attempt did not yield the expected result
<button class="modifysection" data-id="14">modify</button>
<div class="section_edit" style="display: none;" data-id="14"></div>
<script>
$('body').on('click', '.modifysection', function() {
var $this = $(this),
id = $this.attr('data-id');
var section = $('.section_view[data-id=id]');
if(section.style.display == 'none')
section.style.display = 'block';
})
</script>
What mistake am I making?