How to swap out the rel attribute with id in jQuery

Ensuring my webpages are W3C valid is a priority for me. I am taking steps to rectify errors one by one in order to achieve validity. Upon using the HTML5 doctype, an error was flagged.

On Line 348, Column 81: it was pointed out that the RDFa Core attribute rel is not allowed on the li element in HTML5 + RDFa 1.1 Lite documents. It was suggested to consult the HTML5 + RDFa 1.1 schema instead.

In an attempt to address this issue, I replaced rel with id to maintain W3C validation. However, the code did not function as expected. How can I modify the code below to eliminate the use of rel?

<script type="text/javascript">
$(document).ready(function() {
$(".tab_content").hide();
$(".tab_content:first").show(); 
$("ul.tabs li").click(function() {
    $("ul.tabs li").removeClass("active");
    $(this).addClass("active");
    $(".tab_content").hide();
    var activeTab = $(this).attr("rel"); 
    $("#"+activeTab).fadeIn(); 
});
});
</script> 
<ul class="tabs">
<li class="active" rel="tab2">&nbsp;&nbsp;Reviews&nbsp;&nbsp;</li><li rel="tab3">News</li><li rel="tab4">&nbsp;&nbsp;Articles&nbsp;</li></ul>


<div id="tab1" class="tab_content" style="width:326px;">data</div>
<div id="tab2" class="tab_content" style="width:326px;">data tab2</div> 

Answer №1

By manually scanning the HTML code, locate each <li> element and change the attribute rel to id without using JavaScript. Ensure that the id is unique within the page. For example, you can modify them to liTab2, liTab3, etc.

Next, in your jQuery script, update $(this).attr("rel"); to

this.id.replace("li", "").toLowerCase();
.

If there are other specific details you need in the response, please let me know.

Answer №2

When modifying the li elements associated with the tabs, make the following changes:

<li class="active" rel="tab2">&nbsp;&nbsp;Reviews&nbsp;&nbsp;</li>

should now be:

<li class="active" data-target="tab2">&nbsp;&nbsp;Reviews&nbsp;&nbsp;</li>

Additionally, update

var activeTab = $(this).attr("rel");

to:

var activeTab = $(this).data("target");

Keep in mind that this follows jQuery's standard behavior of retrieving HTML5 data-* attributes and assigning them to the object's dataset.

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

Leveraging the power of nodejs functions within static HTML files in expressJs

Being a beginner in Javascript and Nodejs, I am uncertain about the best way to organize my project. I am currently working on creating a web interface for a C++ application using Nodejs and V8 to wrap a C++ API. My question is, can I utilize Express to se ...

Is there a way to extract just the JSON data from res?

While creating a search functionality to display a list of users, I encountered an error when attempting to load additional pages to show more users: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data var result = JSON.pars ...

Leveraging the execute script command in Selenium IDE to determine the time duration between two dates displayed on the webpage

For work automation, I've been utilizing SIDE to streamline certain tasks. One challenge I'm facing involves extracting dates from a page using the store command and then attempting to calculate a duration using the execute script command, which ...

What is the best way to create dynamic transparency based on cursor position?

Is there a way to create an animation like the one on https://meetwalter.com, where the transparency changes with the cursor's position? I previously attempted a similar implementation using CSS, but it seems that the website accomplishes this effect ...

Error in TypeScript: Typography type does not accept 'string' type as valid

As I attempt to implement the Typography component from material-ui using TypeScript, I encounter a perplexing error message TypeScript is throwing an error: Type 'string' is not assignable to type 'ComponentClass<HTMLAttributes<HTMLE ...

Creating JavaScript Objects from HTML Form data with the help of serializeJSON

Struggling extracting HTML form data into the required JSON format for server communication. Despite following a guide, I can't get the output right. Managed to extract question keys and values, but labeling is tricky. Current Output: {"Question1":" ...

What's the best way to arrange a series of images in a horizontal line using html and css?

Looking for a way to display a list of images in a straight line with just the right amount of spacing between them? Check out my fiddle and see the challenge I'm facing. https://i.sstatic.net/ZvICc.png I've been experimenting with HTML c ...

Troubleshooting ngFor in Angular 5

I'm currently working on a component that needs to display data fetched from the server. export class CommerceComponent implements OnInit { dealList; ngOnInit() { this.getDeals(); } getDeals(){ this.gatewayService.se ...

Passing the response from an AJAX request to JavaScript

When I call ajax to retrieve a value from an asp page and return it to the calling javascript, the code looks like this: function fetchNameFromSession() { xmlhttp = GetXmlHttpObject(); if (xmlhttp == null) { alert("Your browser does n ...

Gathering the presently unfinished observables within a superior-level rxjs observable

As an illustration, let's consider a scenario where I have a timer that emits every 5 seconds and lasts for 10 seconds. By using the scan operator, I can create an observable that includes an array of all the inner observables emitted up until now: c ...

Printing in Firefox is ineffective, but functions smoothly in alternative browsers

I'm currently working on customizing some content specifically for printing, so I've implemented a hook import { useState } from 'react' const usePrint = () => { const [isPrinting, setIsPrinting] = useState(false) const hand ...

What is the best way to compare dates in JavaScript using this particular format?

Is there a way to compare the current date and time in JavaScript with the specific format of '2016-06-01T00:00:00Z'? I am receiving the date format '2016-06-01T00:00:00Z' from the backend, and I need to verify it against today's ...

Hovering over the top menu items in AngularJS will reveal dropdown submenus that will remain visible even when moving the cursor

I am facing an issue where my top menu has links that display a dropdown of additional menu items upon hovering. I have attempted to use onmouseover and onmouseleave events to control the visibility of the sub menu. However, I have encountered a problem ...

Challenge with adjusting opacity of background when hovering over a box

I've encountered an issue with the background transparency in the following demo. For some reason, it's not working properly. .figure .caption-mask:hover { background: rgba(0, 0, 0, 0.0); } I'm attempting to remove the opacity f ...

Anticipate the arrival of a gadget and deliver a response to a website

My current project involves utilizing the nfc module from npm to read smartCard data and send the results to a web interface. Everything works smoothly when the card reader is connected. However, when the card reader is not plugged in, the web server (nod ...

Exploring the world of flexbox and experimenting with implementing flex-wrap at a specific breakpoint

I am working on a layout that includes a module containing various content. My goal is to have the progress bar, along with the labels "parts" and "projects," positioned underneath an image and expand to the full width of the module when the window size go ...

Ways to align three divs next to each other in an HTML structure?

I am currently working on a website layout that consists of three sections positioned horizontally. I am aiming for the left division to take up 25% of the width, the middle one to occupy 50% of the width, and the right division to fill 25% of the width so ...

Exploring the world of logging in Nestjs to capture response data objects

I'm eager to implement logging for incoming requests and outgoing responses in NestJs. I gathered insights from various sources including a post on StackOverflow and a document on NestJs Aspect Interception. I'd love to achieve this without rely ...

What could be causing my custom Google font in CSS to not function properly?

I've been trying to change the font-family from Google Fonts in my Bootstrap 5 project, but it's not working as expected. Here's a snippet of my code: HTML <div class="row"> <div class="col-lg-6 col-md-12" ...

Why is my JSON object showing up as undefined in my Node.js POST request?

I have a CentOS server that is currently running a node.js HTTP server (code provided below). My goal is to pass JSON data from the command line by using the following CURL command: curl -X POST -H "application/json" -d '{"val1":"hello","val2":"my"," ...