I wanted to shorten below code in dynamic way.
The code is using to load the number of tags having class name "region1, 2,3, 4" in each section .it loads to corresponding div in side p tag.
Experts please Help.
// Load region based event’s count in region tiles
$(document).ready(function(){
//load count on page load
//Default one on page load
var region1 = $('#tab1 .region1').length;
$(".Regions_latam p").text(region1 + " Events");
console.log(region1);
var region2 = $('#tab1 .region2').length;
$(".Regions_global p").text(region2 + " Events");
var region3 = $('#tab1 .region3').length;
$(".Regions_na p").text(region3 + " Events");
var region4 = $('#tab1 .region4').length;
$(".Regions_emea p").text(region4 + " Events");
var region5 = $('#tab1 .region5').length;
$(".Regions_atci p").text(region5 + " Events");
//Default one on page load ends
$(".tab1").click(function() {
console.log("tab1 clicked");
var region1 = $('#tab1 .region1').length;
$(".Regions_latam p").text(region1 + " Events");
var region2 = $('#tab1 .region2').length;
$(".Regions_global p").text(region2 + " Events");
var region3 = $('#tab1 .region3').length;
$(".Regions_na p").text(region3 + " Events");
var region4 = $('#tab1 .region4').length;
$(".Regions_emea p").text(region4 + " Events");
var region5 = $('#tab1 .region5').length;
$(".Regions_atci p").text(region5 + " Events");
});
$(".tab2").click(function() {
var region1 = $('#tab2 .region1').length;
$(".Regions_latam p").text(region1 + " Events");
var region2 = $('#tab2 .region2').length;
$(".Regions_global p").text(region2 + " Events");
var region3 = $('#tab2 .region3').length;
$(".Regions_na p").text(region3 + " Events");
var region4 = $('#tab2 .region4').length;
$(".Regions_emea p").text(region4 + " Events");
var region5 = $('#tab2 .region5').length;
$(".Regions_atci p").text(region5 + " Events");
});
$(".tab3").click(function() {
var region1 = $('#tab3 .region1').length;
$(".Regions_latam p").text(region1 + " Events");
var region2 = $('#tab3 .region2').length;
$(".Regions_global p").text(region2 + " Events");
var region3 = $('#tab3 .region3').length;
$(".Regions_na p").text(region3 + " Events");
var region4 = $('#tab3 .region4').length;
$(".Regions_emea p").text(region4 + " Events");
var region5 = $('#tab3 .region5').length;
$(".Regions_atci p").text(region5 + " Events");
});
$(".tab4").click(function() {
var region1 = $('#tab4 .region1').length;
$(".Regions_latam p").text(region1 + " Events");
var region2 = $('#tab4 .region2').length;
$(".Regions_global p").text(region2 + " Events");
var region3 = $('#tab4 .region3').length;
$(".Regions_na p").text(region3 + " Events");
var region4 = $('#tab4 .region4').length;
$(".Regions_emea p").text(region4 + " Events");
var region5 = $('#tab4 .region5').length;
$(".Regions_atci p").text(region5 + " Events");
});
});
// View Hide Region based Events
2
Answers
Did this logic help?
May be you can follow the the above logic that may help you dynamically to get your expected output..
You can add like this: logic is create a function with pass either controlname or classname with text to set as parameter.
https://jsfiddle.net/a95zsurg/