getAttribute
Отримання атрибуту елемента DOM на основі імені атрибуту.
Usage
$(selector).getAttribute(attributeName)
Parameters
Name | Type | Details |
---|---|---|
attributeName | string | запитуваний атрибут |
Examples
index.html
<form action="/submit" method="post" class="loginForm">
<input type="text" name="name" placeholder="username"></input>
<input type="text" name="password" placeholder="password"></input>
<input type="submit" name="submit" value="submit"></input>
</form>
getAttribute.js
it('should demonstrate the getAttribute command', async () => {
const form = await $('form')
const attr = await form.getAttribute('method')
console.log(attr) // outputs: "post"
})
Returns
- <String|null>
return
: Значення атрибуту або null, якщо він не встановлений для елемента.