From 38dce68db533940a04639754b6ba7cc31c88932b Mon Sep 17 00:00:00 2001 From: Sven Minio Date: Sun, 17 May 2026 19:52:05 +0200 Subject: [PATCH] Add DOM Attributes --- DOM-Attributes.md | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 DOM-Attributes.md diff --git a/DOM-Attributes.md b/DOM-Attributes.md new file mode 100644 index 0000000..500ea3a --- /dev/null +++ b/DOM-Attributes.md @@ -0,0 +1,110 @@ +* [`attr`](#usage-attr) | [`val`](#usage-val) | [`removeAttr`](#usage-removeattr) | [`prop`](#usage-prop) + +--- + +## .attr + +**Description** +Get the value of an attribute for the first element in the set, or set one or more attributes for every matched element. + +**Parameters** + +* `name` (String): The name of the attribute. +* `value` (String|Number, optional): The value to set. If omitted, the method acts as a getter. + +**Returns** + +* (String): Value of the attribute (if getter). +* (jBase): Current instance for chaining (if setter). + +**Example** + +```javascript +// Get href +const link = $('a.my-link').attr('href'); + +// Set id and title +$('.item').attr('id', 'item-1').attr('title', 'Item One'); +``` + +--- + +## .val + +**Description** +Get the current value of the first element in the set of matched elements or set the value of every matched element. + +**Parameters** + +* `value` (String|Number, optional): The value to set. + +**Returns** + +* (String|Number): The value of the input (if getter). +* (jBase): Current instance (if setter). + +**Example** + +```javascript +// Get input value +const username = $('#username').val(); + +// Set input value +$('#username').val('NewUser'); +``` + +--- + +## .removeAttr + +**Description** +Remove an attribute from each element in the set of matched elements. + +**Parameters** + +* `name` (String): The name of the attribute to remove. + +**Returns** + +* (jBase): Current instance for chaining. + +**Example** + +```javascript +// Remove disabled attribute to enable a button +$('button.submit').removeAttr('disabled'); + +// Remove readonly attribute from an input +$('.input-field').removeAttr('readonly'); +``` + +--- + +## .prop + +**Description** +Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element. This is especially useful for properties that do not map directly to HTML attributes (like `checked`, `disabled`, or `selectedIndex`). + +**Parameters** + +* `name` (String): The name of the property. +* `value` (Any, optional): The value to set. If omitted, the method acts as a getter. + +**Returns** + +* (Any): Value of the property (if getter). +* (jBase): Current instance for chaining (if setter). + +**Example** + +```javascript +// Get checked state of a checkbox +const isChecked = $('#my-checkbox').prop('checked'); + +// Set a checkbox to checked +$('#my-checkbox').prop('checked', true); + +// Set all inputs in a form to disabled +$('form input').prop('disabled', true); + +``` \ No newline at end of file