}
/**
- * Accesses a boolean property on the first matched element.
- *
- * @param key the name of the boolean property to be accessed
+ * Get the value of a property for the first element in the set of matched elements.
*
- * @return <code>true</code> if at least one element is matched and the specified boolean property
- * is set to <code>true</code> on the first matched element; <code>false</code> otherwise
+ * @param key the name of the property to be accessed
+ * @return the value of the property, in the case the property is a 'boolean' it
+ * returns a Boolean object, and a Double if is a 'number', so be prepared
+ * if you cast to other numeric objects. In the case of the property is undefined
+ * it returns null.
+ */
+ public <T> T prop(String key) {
+ assert key != null : "Key is null";
+ return isEmpty() ? null : JsUtils.<T>prop(get(0), key);
+ }
+
+ /**
+ * Get the value of a property for the first element in the set of matched elements.
*
+ * @param key the name of the property to be accessed
+ * @param clz the class of the type to return
+ *
+ * @return the value of the property, it safely check the type passed as parameter
+ * and preform the aproproate transformations for numbers and booleans.
+ * In the case of the property is undefined it returns null.
*/
- public boolean prop(String key) {
- return !isEmpty() && elements[0].getPropertyBoolean(key);
+ public <T> T prop(String key, Class<? extends T> clz) {
+ assert key != null : "Key is null";
+ return isEmpty() ? null : JsUtils.<T>prop(get(0), key, clz);
}
-
+
/**
- * Sets a boolean property to a value on all matched elements.
+ * Sets a property to a value on all matched elements.
*
* @param key the name of the boolean property to be set
- * @param value the value the specified boolean property should be set to
+ * @param value the value specified. In the case the value is a Number, it is set
+ * as a 'number' in the javascript object and the same with Boolean.
*
* @return this <code>GQuery</code> object
*