I have programmed 6 buttons and successfully implemented jQuery to display a block of data upon clicking each button. Is there a way to condense the jQuery code? If so, what is the best approach to achieve this?
$("#button1").click(function() {
$("#text1").show();
$(".close").show();
$(".close").click(function() {
$("#text1").hide();
});
});
... (repeated for all buttons) ...
});
#header {
width: 640px;
height: 480px;
background-color: grey;
}
... (CSS styling continues) ...
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="header">
<div>
<div class="block" id="text1">
... (HTML structure repeated for all buttons) ...
</div>
... (more HTML structure for other buttons) ...
</div>