Is there a method to enable the summary tag in Internet Explorer 11, such as using an external library?
<details>
<summary>Here is the summary.</summary>
<p>Lorem ipsum dolor sit amet</p>
</details>
Appreciate your help.
Is there a method to enable the summary tag in Internet Explorer 11, such as using an external library?
<details>
<summary>Here is the summary.</summary>
<p>Lorem ipsum dolor sit amet</p>
</details>
Appreciate your help.
If you want to use the details
and summary
elements in Internet Explorer, you'll have to do some extra work because IE doesn't support them by default.
You can check if details
and summary
are supported using feature detection like this:
if (typeof HTMLDetailsElement === "undefined") {
// Not supported
}
If not supported, you can create and immediately remove these elements in order to style them:
document.createElement("details");
document.createElement("summary");
After that, add some CSS styling for these elements:
// Basic styling example
var style = document.createElement("style");
style.textContent =
"details > :not(summary) {\n" +
" display: none;\n" +
"}\n" +
"details.showing > :not(summary) {\n" +
" display: block;\n" +
"}\n";
document.querySelector("head").appendChild(style);
Additionally, since not all content within details
defaults to display: block
, you may need to customize the styling further. You can also consider adding visual cues like arrows for better consistency with other browsers.
It's important to place this code before the body
element to prevent any unstyled content flashing on the page initially.
To handle user interactions, such as clicks and keypresses, for details
elements, toggle a class based on the specific styling defined earlier:
// Rough event handling logic
document.addEventListener("click", detailsHandler);
document.addEventListener("keypress", detailsHandler);
function detailsHandler(e) {
if (e.type === "keypress" && [13, 32].indexOf(e.which || e.keyCode) === -1) {
return;
}
var el = e.target;
while (el && el.tagName !== "DETAILS") {
if (el.tagName === "BODY") {
el = null;
break;
}
el = el.parentNode;
}
if (el) {
el.classList.toggle("showing");
}
}
This code snippet doesn't necessarily have to be placed before body
, but it might make organizational sense to keep it together with the initial setup.
Finally, remember to include tabindex="0"
attributes on both details
and summary
elements to ensure they are accessible via keyboard navigation in IE:
<details tabindex="0">
<summary tabindex="0">This is a summary.</summary>
<p>bla bla bla</p>
</details>
Check out the live example below for an illustration of how to implement this workaround in your code:
<!-- In the head element -->
<script>
(function() {
if (typeof HTMLDetailsElement === "undefined") {
// Detect non-support and enable
document.createElement("details");
document.createElement("summary");
document.addEventListener("click", detailsHandler);
document.addEventListener("keypress",
detailsHandler);
var style = document.createElement("style");
style.textContent =
"details > :not(summary) {\n" +
" display: none;\n" +
"}\n" +
"details.showing > :not(summary) {\n" +
" display: block;\n" +
"}\n";
document.querySelector("head").appendChild(style);
}
function detailsHandler(e) {
if (e.type === "keypress" && [13, 32].indexOf(e.which ||
e.keyCode) === -1) {
return;
}
var el = e.target;
while (el && el.tagName !== "DETAILS") {
if (el.tagName === "BODY") {
el = null;
break;
}
el = el.parentNode;
}
if (el) {
el.classList.toggle("showing");
}
}
})();
</script>
<!-- End of in the head element -->
<!-- In body -->
<details tabindex="0">
<summary tabindex="0">This is a summary.</summary>
<p>bla bla bla</p>
</details>
If you're dealing with IE11's lack of support for summary/detail elements, fear not! Here are a couple of polyfills that might help:
I have been working with localStorage for storing and retrieving items in my JavaScript code housed within a .vue file. However, I am now looking to find a way to transfer this stored data into my Vuex store, specifically within the mutations section locat ...
I am looking to create an array that stores the ID of a div and the checked value. Check out this FIDDLE for reference For example, if I check samsung and lenovo under brands, and select 4gb for RAM, the array should be: array[ ] = ["brands" ...
I'm facing an issue with a custom directive in AngularJS that is supposed to draw a circle using SVG. However, upon loading the page, the circle doesn't appear, and even the text within the template is not showing up. What could be causing this ...
$(document).ready(function(){ if ($(window).width() <961){ $('.item').on('click',function(){ /*---do something---*/ }) }else{ $('.item').on('click',function(){ ...
I created a simple dropdown using a <div> (parent), <span> (current selection), and <ul> (options) which is functioning properly. Now, I'm looking to enhance it by implementing a feature that allows the dropdown to close when the use ...
<div id="wormGearTabulatorTable" style="max-height: 100%; max-width: 100%; position: relative;" class="tabulator" role="grid" tabulator-layout="fitDataTable"><div class="tabulator-header" role="rowgroup"><div class="tabulator-header-co ...
I have a requirement where I need to store a list of objects (each with a unique id) as a session parameter. These objects are then displayed in a table in a JSP using JSTL. <c:forEach var="list" items="${PlayerList}"> <tr> <td> ...
<input type="checkbox" name="smoker"> Is there a way for JavaScript to determine whether the checkbox is checked or unchecked without making changes to the HTML code above? ...
I am attempting to target all elements having the class .select that are nested somewhere within the DOM tree. The only condition is that these elements should not have any ancestors with the class .forbidden. This means it will not detect any elements ...
I am currently in the process of developing a calendar using HTML, CSS, and JavaScript. The main purpose of this calendar is to showcase upcoming and past events. However, I am facing difficulties in ensuring that my event blocks occupy the remaining space ...
Whenever I attempt to upload an image from my existing files, everything goes smoothly. However, if I try to select a file by directly clicking on the camera icon on my mobile device, it fails with a "CORS Error" message. I have tried adding and removing t ...
I have a challenge with creating toggle buttons that require specific functions: 1) Display content on the first click (this is working) 2) Conceal content when another button is clicked (this is also working) 3) Hide content on the second click (this i ...
I currently have an active express server that is sending data using res.write() Fetcher.js function fetcher() { console.log("fetcher function called") fetch('/units.html', { method: "POST", body: JSO ...
How do I store the URL of an image uploaded to Firebase Storage in Firebase Database? When executing the code below, I encounter the following error: Uncaught (in promise) FirebaseError: Function DocumentReference.set() called with invalid data. Unsuppor ...
Encountering an error when attempting to render a file from the 'views' directory in the 'routes'. The specific error message is as follows: Error: Valid Login { [Error: ENOENT: no such file or directory, open './views/s ...
Hello there! I am currently working on retrieving data from a webpage that is updated using Javascript. Initially, I attempted to create a Java program to periodically fetch this page from the server, but the information was being updated too slowly. The ...
I recently started working on a basic Vue project. The project involves integrating a Google Map using the vue2-google-maps package. Additionally, I have a JSON file (or data.php) containing the following information: { "locations": [ { "nam ...
I am trying to implement pagination for the results of an API call. The following code snippet shows how I am making the API call using Axios: apiCall() { const API = `http://www.omdbapi.com/`; axios.get(API, { params: { apikey: proces ...
button, a { height: 30px; display: inline-block; border: 1px solid black; vertical-align: middle; } button > div, a > div { width: 30px; height: 10px; background-color: red; } <button> <div class="buttonDiv"></div> ...
var express = require('express'); var app = express(); var pg = require('pg'); var connectionString = "postgresql://postgres:sujay123@localhost:3001/redc"; app.use(express.static('public')); app.get('/index.h ...