<script> function hideAllInfoParagraphs() { var infoParagraphs =…
- User
- Assistant
- User
the code is not working anymore
- Assistant
the code is not working anymore
Certainly! If you want the "all" category to follow the same behavior as the other categories, namely hiding the info paragraphs and not displaying them, you don't need to apply any specific conditions for "all" when it comes to handling info paragraphs. Your filterRows function already hides all info paragraphs initially through hideAllInfoParagraphs() regardless of the selected category.
However, if your goal is to ensure that the "all" category specifically does not trigger any change that might cause info paragraphs to display elsewhere in your script or due to other interactions, simply maintaining the initial call to hideAllInfoParagraphs() at the start of the filterRows function suffices, because it ensures that no info paragraphs are shown when any category is selected, including "all".
If the original code provided correctly hides all the information paragraphs initially and you want to ensure that selecting "all" maintains this state without changing the behavior specifically for "all", no modifications are needed.
Here's a slight refinement to ensure the clarity of intent without introducing redundancy, assuming there's no other part of the script intended to show info paragraphs only when "all" is selected:
<script>
function hideAllInfoParagraphs() {
var infoParagraphs = document.getElementsByClassName("info-paragraph");
for (var i = 0; i < infoParagraphs.length; i++) {
infoParagraphs[i].style.display = 'none'; // Hide all info paragraphs
}
}
function filterRows(category) {
var rows = document.getElementsByClassName("et_pb_row");
hideAllInfoParagraphs(); // Hide all info paragraphs
// Loop through rows to adjust display based on category
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (category === 'all' || row.classList.contains(category)) {
row.style.display = 'block'; // Show rows that match the category, including 'all'
row.style.opacity = '1'; // Ensure the row is fully visible
} else {
row.style.display = 'none'; // Hide rows not matching the category
row.style.opacity = '0'; // Though 'display: none' suffices, opacity is reset for consistency
}
}
}
window.onload = function() {
hideAllInfoParagraphs(); // Ensure info paragraphs are hidden when page loads
};
</script>
This version makes it clear that the expectation for selecting "all" is the same as selecting any other category regarding info paragraphs—they remain hidden. The visibility changes apply uniformly to rows based on category membership without creating special cases for info paragraph visibility.
If the modified script is not working as expected, it might be due to several reasons. It's critical to ensure that all your functions and event handlers are correctly set up and that the script fits well within the context of your HTML structure. Let's troubleshoot common issues and ensure the JavaScript integrates properly with your webpage.
First, always check the web browser’s developer console for errors. JavaScript errors can halt script execution, causing unexpected behavior. Rectify any errors that the console points out.
Make sure the script is placed correctly within your HTML file. If the script is placed in the <head> without window.onload or before your elements are defined in the body, it might try to manipulate elements that aren't yet available in the DOM. However, your existing script uses window.onload, which should mitigate this issue. Ensure that this part of the script has not been inadvertently modified.
Ensure all class names used in your JavaScript match those in your HTML elements. A single typo can cause the script to fail. Your function targets elements with specific class names (info-paragraph, et_pb_row, and different categories including hospitality, residential, etc.). Double-check these class names in your HTML.
Here's a simplified and verified version of your script. This assumes you have HTML elements with class names like info-paragraph and et_pb_row, and your categories are appropriately assigned as classes to those et_pb_row elements.
<script>
function hideAllInfoParagraphs() {
var infoParagraphs = document.getElementsByClassName("info-paragraph");
for (var i = 0; i < infoParagraphs.length; i++) {
infoParagraphs[i].style.display = 'none';
}
}
function filterRows(category) {
var rows = document.getElementsByClassName("et_pb_row");
hideAllInfoParagraphs(); // Call at the start to ensure all info paragraphs are hidden
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
// Display block if category matches or 'all' is selected.
if (category === 'all' || row.classList.contains(category)) {
row.style.display = 'block';
row.style.opacity = '1';
} else {
row.style.display = 'none'; // If not matching, hide
}
}
}
// Ensure elements are manipulated after the DOM is fully loaded
window.onload = function() {
hideAllInfoParagraphs();
};
</script>
To further assist, I'd need to see how you're calling filterRows (e.g., via buttons or links). The call should look something like this within your HTML:
<button onclick="filterRows('all')">Show All</button>
<button onclick="filterRows('hospitality')">Hospitality</button>
<button onclick="filterRows('residential')">Residential</button>
<!-- Add other categories as needed -->
Ensure that the calls to filterRows are correctly passing the intended category as an argument.
If the script still isn't working as expected, please provide more details about how it's failing and any other context (e.g., HTML structure, specific behaviors you're observing, errors in the console, how you're invoking filterRows, etc.), as that will help in diagnosing the issue more precisely.
Not yet included in a published release.