Beginner Friendly · Hands-on · Free

get the value of an attribute on an element

Javascript இல் getAttribute() method இங்கு ஒரு குறிப்பிட்ட html element இல் அமைந்திருக்கும் ஒரு attribute இன் value ஐ எடுப்பதற்கு பயன்படுகிறது

5 min read Updated Dec 13, 2025

JavaScript getAttribute

Javascript இல் getAttribute() method இங்கு ஒரு குறிப்பிட்ட html element இல் அமைந்திருக்கும் ஒரு attribute இன் value ஐ எடுப்பதற்கு பயன்படுகிறது.

element.getAttribute(name);

Note: இங்கு setAttribute() method இல் இங்கு ஒரு குறிப்பிட்ட html element இல் அமைந்திருக்கும் ஒரு attribute இன் value ஐ எடுப்பதற்கு பயன்படுகிறது. இங்கு நாம் கண்டறிய வேண்டிய attribute இன் key name ஆனது argument ஆக அனுப்புகிறோம். இந்த method மூலம் நாம் எளிதாக ஒரு html element இன் attribute value ஐ கண்டறியலாம்.

Example1


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JS getAttribute() Demo</title>
</head>
<body>
    <button id="btnSend" name ="success">Send</button>
<script>
        let btnSend = document.querySelector('#btnSend');
        if (btnSend) {
           var res = btnSend.getAttribute('name');
           console.log(res);
        }
</script>
</body>
</html>

மேலே உள்ள Example1-ஐ கவனிக்கவும் இங்கு html tag கள் கொடுக்கப்பட்டுள்ளது. இங்கு document.querySelector('#btnSend') என்ற method மூலமாக நாம் ஒரு குறிப்பிட்ட element ஐ select செய்து கொள்கிறோம். பிறகு அதனை btnSend என்ற variable இல் store செய்து கொள்கிறோம். இங்கு btnSend.getAttribute('name') என்ற getAttribute method மூலமாக இங்கு name என்ற attribute இன் value ஆனது நமக்கு கிடைக்கிறது. இங்கு நமக்கு success என்ற output கிடைக்கிறது.

Output:

success

Example2


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JS getAttribute() Demo</title>
</head>
<body>
    <button id="btnSend" name ="send">Send</button>
<script>
        let btnSend = document.querySelector('#btnSend');
        if (btnSend) {
           var res = btnSend.getAttribute('name');
           console.log(res);
        }
</script>
</body>
</html>

மேலே உள்ள Example2-ஐ கவனிக்கவும் இங்கு html tag கள் கொடுக்கப்பட்டுள்ளது. இங்கு document.querySelector('#btnSend') என்ற method மூலமாக நாம் ஒரு குறிப்பிட்ட element ஐ select செய்து கொள்கிறோம். பிறகு அதனை btnSend என்ற variable இல் store செய்து கொள்கிறோம். இங்கு btnSend.getAttribute('name') என்ற getAttribute method மூலமாக இங்கு name என்ற attribute இன் value ஆனது நமக்கு கிடைக்கிறது. இங்கு நமக்கு send என்ற output கிடைக்கிறது.

Output:

send

இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.