Response title
This is preview!
I am working on web accessibility.
I need to change(set if not exist) aria-hidden attribute when call JQuery Show()/Hide() functions. This is showHide function from JQuery 1.9.1
I added only 2 lines of code:
elem.setAttribute("aria-hidden", "true");
This
is working but I am not sure will this work in
all browsers?
http://www.w3schools.com/jsref/met_element_setattribute.asp It
looks that IE8 an earlier does not support setAttribute
method.
function showHide(elements, show) {
var display, elem, hidden,
values = [],
index = 0,
length = elements.length;
for (; index < length; index++) {
elem = elements[index];
if (!elem.style) {
continue;
}
values[index] = jQuery._data(elem, "olddisplay");
display = elem.style.display;
if (show) {
// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if (!values[index] && display === "none") {
elem.style.display = "";
}
// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if (elem.style.display === "" && isHidden(elem)) {
values[index] = jQuery._data(elem, "olddisplay", css_defaultDisplay(elem.nodeName));
}
elem.setAttribute("aria-hidden", "false");
} else {
if (!values[index]) {
hidden = isHidden(elem);
if (display && display !== "none" || !hidden) {
jQuery._data(elem, "olddisplay", hidden ? display : jQuery.css(elem, "display"));
}
}
elem.setAttribute("aria-hidden", "true");
}
}
..............
......................
return elements;
}
Use these like
$(mySelector).myShow();
$(mySelector).myHide();
© 2013 jQuery Foundation
Sponsored by and others.