JSFiddle - React, Tailwind, and code Playground

by cordeliaf

HTML

<article>
<header>
    <h2>Top ten reasons to take a course!</h2>
    <span class="author">JK</span>
    <class="date">March 20th</span>
</header>
    <ol id="reasons">
        <li>It's fun</li>
        <li>Learn a lot</li>
        <li>Advance carrer</li>              
    </ol>    
</article>

JavaScript

var topList = document.getElementById("reasons");
var reasons = topList.getElementsByName("li");

//for(var i = 0; i< reasons.length; i++){
//    alert(reasons[i].textContent);
//}

for (var el = topList.firstElementChild; el; el=el.nextElementSibling)
   // alert(el.textContent);
    if(el.classList.contains("best")) {
       alert("The best reason to take a course is "+ el.textContent");}
}