I have a wordpress website where in one page i have several member profiles that appear on different sections of the page. The theme I'm using uses CMSMasters Content Composer as the page builder. They have a Profiles area where i can create different profiles with their description. Each profile also as a subtitle that is going to show on the front-end every time i use the profile element on the page builder.
There is a page where i use several times this profiles and my objective is for a specific profile to have different subtitles in each section. There is three sections that i would like to change the subtitle of a specific profile. The default subtitle for the profile i want to change is 'Direção Artística'.
I've added class names for each of the profiles elements and i'm trying to create code that will change the subtitle depending on the section.
I'm using a code snippet to add the code to the page.
Code:
document.addEventListener('DOMContentLoaded', function() {
const profile9572 = document.getElementById('post-9572');
if (profile9572) {
const subtitle = profile9572.querySelector('.pl_subtitle');
const section = profile9572.closest('.cmsmasters_profile');
console.log(section); // Add this line to check the value of 'section'
console.log('Class list', section.classList);
if (section.classList.contains('escolaprofiles')) {
subtitle.textContent = 'Contemporâneo e Dança Inclusiva';
} else if (section.classList.contains('somaprofiles')) {
subtitle.textContent = 'Dança Inclusiva';
} else if (section.classList.contains('corpoprofiles')) {
subtitle.textContent = 'Direção Artística';
}
}
});
So, the code works until it reaches the class 'escolaprofiles' after that it doesn't go the the next conditional where it should find the class name somaprofiles and change the subtitle of the 'profile9572'
In the front-end you can see that it changed from 'Direção Artística' to 'Contemporâneo e Dança Inclusiva' but it does't go the the next condition.
there is no typos, if i do a 'console.log('Class list', section.classList);' you can see that it calls the classes correctly but i don't understand why it's not going to the next condition.
URL where you can see this live: https://www.dancaleiria.pt/quemsomos/#equipa
Please i would love advice on what I'm doing wrong.
There is a page where i use several times this profiles and my objective is for a specific profile to have different subtitles in each section. There is three sections that i would like to change the subtitle of a specific profile. The default subtitle for the profile i want to change is 'Direção Artística'.
I've added class names for each of the profiles elements and i'm trying to create code that will change the subtitle depending on the section.
I'm using a code snippet to add the code to the page.
Code:
document.addEventListener('DOMContentLoaded', function() {
const profile9572 = document.getElementById('post-9572');
if (profile9572) {
const subtitle = profile9572.querySelector('.pl_subtitle');
const section = profile9572.closest('.cmsmasters_profile');
console.log(section); // Add this line to check the value of 'section'
console.log('Class list', section.classList);
if (section.classList.contains('escolaprofiles')) {
subtitle.textContent = 'Contemporâneo e Dança Inclusiva';
} else if (section.classList.contains('somaprofiles')) {
subtitle.textContent = 'Dança Inclusiva';
} else if (section.classList.contains('corpoprofiles')) {
subtitle.textContent = 'Direção Artística';
}
}
});
So, the code works until it reaches the class 'escolaprofiles' after that it doesn't go the the next conditional where it should find the class name somaprofiles and change the subtitle of the 'profile9572'
In the front-end you can see that it changed from 'Direção Artística' to 'Contemporâneo e Dança Inclusiva' but it does't go the the next condition.
there is no typos, if i do a 'console.log('Class list', section.classList);' you can see that it calls the classes correctly but i don't understand why it's not going to the next condition.
URL where you can see this live: https://www.dancaleiria.pt/quemsomos/#equipa
Please i would love advice on what I'm doing wrong.