JSFiddle - React, Tailwind, and code Playground

by Prakash Upadhyay

HTML

<div id="foo">Example 1</div>
<p></p>
<span>1</span>

<div id="foo2">Example 2</div>
<span>2</span>
<span>3</span>

<div>Example 3</div>
<div class="check">
<input type="checkbox" class="checkbox">
 <span class="chk-lbl">label</span>
</div>
    
    
<div class="check">
 <input type="checkbox" class="checkbox">
 <span class="chk-lbl">label</span>
</div>

JavaScript

//example 1
$('#foo').nextAll('span:first').css('color', 'red');

//example 2
$('#foo2 ~ span:first').css('color', 'blue');

//example 3
$('.checkbox').click(function(){

    if(this.checked == true){
           // alert("yes");
        $(this).next().css('color','red');
    }else{
        //alert("no");
        $(this).next().css('color','black');
    }
});