Home > Web Front-end > JS Tutorial > Does Internet Explorer 6 Support Accessing Custom Data Attributes?

Does Internet Explorer 6 Support Accessing Custom Data Attributes?

Linda Hamilton
Release: 2024-11-15 05:56:02
Original
942 people have browsed it

Does Internet Explorer 6 Support Accessing Custom Data Attributes?

Custom Data Attributes in Internet Explorer 6

Querying custom data attributes in HTML5 is a widely supported feature, but its compatibility with legacy browsers can be uncertain. This article investigates whether Internet Explorer 6 supports accessing data-prefixed attributes like "data-geoff" using JavaScript.

The Problem

In HTML5, custom data attributes allow developers to extend elements with non-standard key-value pairs. For instance, the following code creates a div element with a "data-geoff" attribute:

<div>
Copy after login

The Question

Can JavaScript access the value of "data-geoff" using the following code in Internet Explorer 6?

var geoff = document.getElementById('geoff');
alert(geoff.dataGeoff);
Copy after login

The Answer

Contrary to popular belief, Internet Explorer 6 does support retrieving custom attribute values. To do so, use the getAttribute() method, as demonstrated below:

var geoff = document.getElementById('geoff');
alert(geoff.getAttribute('data-geoff'));
Copy after login

In IE6, this code will display "geoff de geoff" in an alert box.

It's important to note that this behavior is not specific to HTML5 attributes. IE6 supports accessing any custom attribute prefixed with "data-".

The above is the detailed content of Does Internet Explorer 6 Support Accessing Custom Data Attributes?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template