Utilizing a "secret" class instead of display: none for managing Tabs in Jquery

After researching screen readers and accessibility, I am interested in incorporating tab navigation into a website I am currently working on. However, I have concerns about data indexing, SEO, and accessibility issues. I am currently using a "hidden" class for the content based on HTML5 boilerplate and a CSS tricks article.

$(".ServButt").click(function() {
    $("#Amenities").addClass("hidden");
    $("#Services:visible").removeClass("hidden");
});
$(".AmenButt").click(function() {
    $("#Services").addClass("hidden");
    $("#Amenities:visible").removeClass("hidden");
});
.hidden {
    position: absolute;
    width: 1px;
      /* Setting this to 0 make it invisible for VoiceOver */
    height: 1px;
      /* Setting this to 0 make it invisible for VoiceOver */
    padding: 0;
    margin: -1px;
    border: 0;
    clip: rect(0 0 0 0);
    overflow: hidden;
}

.AmenButt,
    .ServButt {
    cursor: pointer;
    background: grey;
    padding: 10px;
    color: white;
    margin-bottom: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="AmenButt">Amenities</div>
<div class="ServButt">Service</div>
<div class="" id="Amenities">
    <p><b>AMENITIES</b> Improving quality mobilize planned giving natural resources; enabler momentum disruption citizenry. Kickstarter; theory of social change change-makers Angelina Jolie climate change. Evolution worldwide, contribution agriculture nonprofit, tackle rural forward-thinking. Policymakers, cause Andrew Carnegie catalytic effect reduce child mortality women and children. Combat malaria meaningful; international development campaign diversification. Hack socio-economic divide legal aid Nelson Mandela Rockefeller. Bono emergent fight against oppression celebrate transformative urb an institutions. Results solution assessment expert engage environmental stakeholders protect, overcome injustice donate. Agency microloans, social impact, care challenges of our times healthcare truth crisis management. Public sector, significant public institutions, pathway to a better life maximize.</p>
</div>
<div class="hidden" id="Services">
    <p><b>SERVICES</b> Giving affordable health care human potential foster democracy effect. Immunize, thinkers who make change happen assessment expert growth underprivileged plumpy'nut gender equality carbon rights. Positive social change policymakers activist tackling maximize altruism. Results celebrate outcomes governance crisis management fighting poverty. Care, assistance, medical supplies; peace turmoil; maintain emergent nonviolent resistance. Citizens of change volunteer effectiveness necessities vaccine; implementation planned giving public service life-expectancy. Billionaire philanthropy, public sector The Elders, visionary Peace Corps fight against oppression vulnerable population. Recognition committed sustainable future focus on impact affiliate proper resources agenda. Martin Luther King Jr. change lives efficient involvement respond poverty. Theory of.</p>
</div>

In the code snippet above, you can see my current approach. I am wondering if there is a more effective way to achieve the same result. I am new to jQuery and looking to improve my skills. I believe there may be variables and conditional codes that could be used with "if" statements to optimize the process. Hopefully, this question can also benefit others looking to implement a simple tab with accessibility features.

Thank you.

Answer №1

When it comes to ensuring that visually hidden content is accessible to screen reader users, the challenge lies in providing clear indications of which content corresponds to the current tab. The use of display:none can effectively hide content from sighted users, but this approach may not always be user-friendly for those relying on screen readers.

In cases where content is duplicated, as in your situation, screen reader users can discern the relevant information. However, with generic tabs or an abundance of content within tabs, navigating through all the material to locate a specific tab can be cumbersome for screen reader users.

Additionally, if tab content includes interactive elements like links or buttons, keyboard-only users may encounter difficulties navigating through off-screen content. This highlights the importance of maintaining accessibility across different modes of interaction.

Therefore, adopting the practice of using display:none to conceal inactive tab content is advisable. By applying this technique thoughtfully, you can ensure that both visual and non-visual users have a seamless browsing experience while still allowing search engines to index the hidden content.

Answer №2

In the past, hidden content with display:none was often overlooked to prevent spammers from using it for malicious purposes.

However, as CSS design evolves, hiding elements has become more common. Google now attempts to properly render websites and determine which hidden layers will be visible to users. It may choose to index layers that are not currently displayed if JavaScript events could reveal them.

To make sure Google recognizes your hidden layers as legitimate content and not spam, ensure that your CSS and JS files are accessible for crawling.

Keep in mind that this system is not foolproof. You can use the "Fetch as Googlebot" feature in Webmaster Tools to verify that all your content is being detected.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Associating specific information with individual elements utilizing HTML text box

Seeking guidance on implementing annotations feature for a scatter-plot using d3.js v3. My goal is to show a text-box upon clicking each data point, then display that entered text as a tool-tip specific to that data point. Here's how I'm approach ...

The Table and Div elements do not have identical widths when set to 100%

I am facing an issue with a Div and Table placed inside a container. Although they are meant to completely fill the container, occasionally there is a one pixel difference which can be quite annoying. I have prepared a test case and attached a screenshot h ...

Retrieving form data from previous page using PHP mail function

Currently, I have a form that needs to be filled out on one PHP page with the following structure: <p> <label for="first_name">First Name: </label> <input type="text" size="30" name="first_name" id="first_name"/> </p> < ...

Multiplying values with different units in CSS calc() function

In my SASS code, I have created a mixin for responsive-self-resizing font size. Here is the code: @mixin fluid-text($min-screenwidth, $max-screenwidth, $min-fontsize, $max-fontsize){ font-size: calc( (#{$min-fontsize}) + (#{$max-fontsize} - #{$min ...

Is it possible to define a multiplication margin using css?

I am trying to place a box in the center of a container, but I am unable to set a static height for the parent element as it may change. This is causing issues with aligning the box perfectly in the middle of the page. Any assistance would be greatly app ...

Adjust the width of a modal in Bootbox for a specific modal only

Currently, I am successfully using Bootbox 4 along with Bootstrap 3 on IE (IE 8 / IE 9) without any issues. In Bootstrap 3, it seems that you can adjust the modal width using CSS like this, but the drawback is that this change will apply to all modals: . ...

What is the best way to ensure an image stays behind another image when it is being

Edit: Here I've successfully kept it in the background while selected, however, it seems to have become unmovable. What could be causing this issue? I have the capability to upload an image from my computer and then move it around. The issue: When I ...

Experiencing difficulties with positioning text beside an image

Hello everyone, I'm a first-time poster seeking some assistance. I'm currently tackling an assessment and am struggling with the final part. The task involves creating a picture card with an image at the top, a circular image to the side, and tex ...

Evaluating h1 content in HTML using Angular Protactor testing

I am completely new to end-to-end testing. I have a login page in my application that should be displayed to users when they log out. However, I am facing an issue with retrieving the text from a specific div element containing an h1 tag, leading to unexpe ...

What is the process for converting a CSS URL to base64 encoding?

Is there a way to convert a css url to base64? For example: <link rel="stylesheet" href="data:text/css;base64,Ym9keSB7IHdpZHRoOiA5NjBweDsgbWFyZ2luOiBhdXRvO30gcCB7IGZvbnQtZmFtaWx5OiBWZXJkYW5hO30" type="text/css"> ...

Angular has the feature of a right float button with *ngfor

I've successfully implemented a form using Reactive Forms in Angular. Currently, my form is displayed as follows: <div class="center" appMcard> <form [formGroup]="GroupRMPM_FG"> <div formArrayName="GroupId_Name" *ngFor="let ...

Click on an element with specific criteria that is located within various parent and child elements using Selenium

In my Python Selenium script, I am attempting to click on an element <a class="clean" href="url"> under the condition that specific elements have certain values. These elements are <div data-passendheid="Correct"> ...

Deactivating multiple buttons in JavaScript after a single click: A guide

After experimenting, I've discovered a solution to my issue. I want to deactivate the option buttons in my quiz application once the user has made a selection. The reason for this is because if the correct answer is revealed and the user selects any ...

How can I convert a list of checkboxes, generated by ng-repeat, into multiple columns?

Here is the HTML code snippet: <div class="checkbox"> <label> <input type="checkbox" ng-model="selectedAll.value" ng-click="checkAll()" />Check All </label> </div> <div class="checkbox" ng-repeat="carType i ...

Customize the Vuetify 2.0 sass variable $heading-font-family

I'm currently trying to customize the default variable $heading-font-family in Vuetify 2.0.0-beta.0, but I'm encountering issues with this particular override. Oddly enough, I have been successful in overriding other variables such as $body-font- ...

How can I display different divs based on a selected option?

I'm encountering difficulties while attempting to develop the code for this specific task. My goal is to display or hide divs based on the selection made in a select option, with a total of 4 options available. There are 2 select elements <select ...

What is the best approach for adding text to an image using TCPDF?

I am trying to create dynvouchers PDF using TCPDF. However, I am facing an issue where the PDF generated does not include the username and password. Here is my code: $html = ''; $html .= '<table><tr>'; for ($a = 1; $a <= ...

The JS content failed to load into the HTML page

I need help creating a workout tracker using two JS files. The main.js file is responsible for loading content from the second file (workoutTracker.js) into the index.html. However, I'm facing an issue where the content is not being displayed on the p ...

How can the HTML DOM be used to implement a dynamic table with a drop feature?

I am struggling to capture the drop event, and I'm unable to do so. Please assist me. I need the savechanges() function to be triggered with every drop action. $('#drag').sortable(); function savechanges() { var table = document.getEleme ...

Switching icon images using JQuery based on state changes

I'm attempting to switch the background image of my webpage's "body" element when the user toggles between playing and pausing music icons. This is what the CSS for the "body" element looks like: body { background: url('https://s3-us-wes ...