getAttribute
Ottieni un attributo da un elemento DOM basato sul nome dell'attributo.
Utilizzo
$(selector).getAttribute(attributeName)
Parametri
Nome | Tipo | Dettagli |
---|---|---|
attributeName | string | attributo richiesto |
Esempi
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"
})
Restituisce
- <String|null>
return
: Il valore dell'attributo, o null se non è impostato sull'elemento.