ডिओএম এলিমেন্টে ক্লাস যোগ করতে প্রথমে querySelector, getElementById ইত্যাদি দিয়ে এলিমেন্টটি খুঁজে বের করতে হয়। তারপর ক্লাস যোগ করতে হয়।
উদাহরণ
<!DOCTYPE html>
<html>
<head></head>
<body>
<p id="para">This is some text</p>
</body>
</html>
এলিমেন্ট খুঁজে বের করার দুটি পদ্ধতি:
querySelector
let myPara = document.querySelector('#para');
getElementById
let myPara = document.getElementById('para');
তারপর ক্লাস যোগ করুন:
let myPara = document.getElementById('para');
myPara.classList.add('myClass');