if (e.getNodeType() != 1) {
continue;
}
- e.removeAttribute(key);
if (JsUtils.hasProperty(e, key)) {
if (BOOLEAN_ATTR_REGEX.test(key)) {
e.setPropertyBoolean(key, false);
e.setPropertyObject(key, null);
}
}
+ e.removeAttribute(key);
}
}
}
/**
- * Check if an object have already a property with name <code>name</code>
+ * Check if an object has already a property with name <code>name</code>
* defined.
*/
public static native boolean hasProperty(JavaScriptObject o, String name)/*-{
return o && name in o;
}-*/;
-
+
+ /**
+ * Check whether an element has an attribute, this is here since GWT Element.getAttribute
+ * implementation returns an empty string instead of null when the attribute is not
+ * present
+ */
+ public static native boolean hasAttribute(JavaScriptObject o, String name)/*-{
+ return !!(o && o.getAttribute(name));
+ }-*/;
+
/**
* Hyphenize style property names. for instance: fontName -> font-name
*/
assertEquals("disabled", ie.getAttribute("disabled"));
}
+
+ public void testAttr_Issue165() {
+ $(e).html("<a href='#' title='a title'>anchor</a>");
+ Element a = $("a", e).get(0);
+
+ assertEquals("a title", a.getAttribute("title"));
+ assertTrue(JsUtils.hasAttribute(a, "title"));
+
+ $(a).removeAttr("title");
+ assertEquals("", a.getAttribute("title"));
+ assertFalse(JsUtils.hasAttribute(a, "title"));
+ }
@DoNotRunWith({Platform.Prod})
// FIXME: the hidden part does not work in FF nor Chrome