জয়েন লগইন

জাভাস্ক্রিপ্ট even

🌈জাভাস্ক্রিপ্ট even কি?

📋জাভাস্ক্রিপ্ট even হলো জোড় অবস্থানের এলিমেন্ট সিলেক্ট করার পদ্ধতি।

⚒️জাভাস্ক্রিপ্ট even জোড় অবস্থানের এলিমেন্ট সিলেক্ট করতে ব্যবহৃত হয়।

জাভাস্ক্রিপ্ট even জোড় অবস্থানের এলিমেন্ট সিলেক্ট করার উদাহরণ।

javascript
<!DOCTYPE html>
<html>
<body>

<button onclick="execute()">ক্লিক করুন</button>
<ul>
  <li>পিএইচপি</li>
  <li>জাভা</li>
  <li>পাইথন</li>
  <li>জাভাস্ক্রিপ্ট</li>
</ul>

<script>
function execute() {
  document.querySelectorAll("li:nth-child(odd)").forEach(function(element) {
    element.style.backgroundColor = "tomato";
  });

  document.querySelectorAll("li:nth-child(even)").forEach(function(element) {
    element.style.backgroundColor = "orange";
  });
}
</script>

</body>
</html>