I have list of Areas .
When i click on any area it should get items related to that specific area .
I have a javascript for that .
The above code was suggested by a bytes member Anas Mosaad and this is working fine .
What i want to ask is that , are there any other better methods to do this ?
Because you can see the javascript above , which has repeated as many times as number of links are
displayed . There might be more number of links in my site and on different pages . So copying same code everywhere isn't worth right ?
So was looking for loop type of script such that any link is clicked , it gets data related to that .
And also i need a transition on changing data in that div tag .
Suggestions are appreciated . Thank you .
Code:
<ul>
<li><a class="my-button" id="a1" href="#">Area1</a></li>
<li><a class="my-button" id="a2" href="#">Area2</a></li>
<li><a class="my-button" id="a3" href="#">Area3</a></li>
<li><a class="my-button" id="a4" href="#">Area4</a></li>
<li><a class="my-button" id="a5" href="#">Area5</a></li>
</ul>
I have a javascript for that .
Code:
<script>
$(document).ready(function() {
$('body').on('click', '#a1', function() {
$("#display").load("area.php?areaid=1");
});
});
</script>
<script>
$(document).ready(function() {
$('body').on('click', '#a2', function() {
$("#display").load("area.php?areaid=2");
});
});
</script>
<script>
$(document).ready(function() {
$('body').on('click', '#a3', function() {
$("#display").load("area.php?areaid=3");
});
});
</script>
<script>
$(document).ready(function() {
$('body').on('click', '#a4', function() {
$("#display").load("area.php?areaid=4");
});
});
</script>
<script>
$(document).ready(function() {
$('body').on('click', '#a5', function() {
$("#display").load("area.php?areaid=5");
});
});
</script>
What i want to ask is that , are there any other better methods to do this ?
Because you can see the javascript above , which has repeated as many times as number of links are
displayed . There might be more number of links in my site and on different pages . So copying same code everywhere isn't worth right ?
So was looking for loop type of script such that any link is clicked , it gets data related to that .
And also i need a transition on changing data in that div tag .
Suggestions are appreciated . Thank you .
Comment