getAttribute प्राप्त करें
विशेषता नाम के आधार पर DOM-एलिमेंट से विशेषता प्राप्त करें।
उपयोग
$(selector).getAttribute(attributeName)
पैरामीटर्स
नाम | प्रकार | विवरण |
---|---|---|
attributeName | string | अनुरोधित विशेषता |
उदाहरण
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"
})
रिटर्न
- <String|null>
return
: विशेषता का मान, या null यदि यह एलिमेंट पर सेट नहीं है।