JSFiddle - React, Tailwind, and code Playground

by bontoJR

HTML

<div>
    <div id="item" data-foo="bar">
    </div>
    <div id="content">
        
    </div>
    <br/>
    <ul>
        <li><a href="#" id="printStatus">Print Status</a></li>
        <li><a href="#" id="btnChangeData">Change Data</a></li>
        <li><a href="#" id="btnChangeAttribute">Change Attribute</a></li>
        <li><a href="#" id="printHTML">Print HTML</a></li>
    </ul>
</div>

CSS

hr {
    color: #333;
    background-color: #333;
    height: 1px;
}

ul {
    margin-left: 0;
    padding-left: 0;
    display: inline;
}

ul li {
    margin-left: 0;
    padding: 3px 5px;
    list-style: none;
    display: inline;
 }

JavaScript

$(document).ready(function () {
    var counter = 2;
    $('#printStatus').click(function (e){
        text="";
        text+="data-foo from data(): " + $('#item').data('foo')+"<br/>";
        text+="data-foo from attr(): " + $('#item').attr('data-foo')+"<br/>";
        text+="<hr/>";
        $('#content').append(text);
    });
    
    $('#printHTML').click(function (e){
        text=$('#item')[0].outerHTML.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        text+="<hr/>"
        $('#content').append(text);
    });
    
    $('#btnChangeData').click(function (e){
        $('#item').data('foo', 'bar' + counter);
        
        text="data changed to " + 'bar' + counter;
        text+="<hr/>";
        $('#content').append(text);
        counter++;
    });
    
    $('#btnChangeAttribute').click(function (e){
        $('#item').attr('data-foo', 'bar' + counter);
        
        text="attribute changed to " + 'bar' + counter;
        text+="<hr/>";
        $('#content').append(text);
        counter++;
    });

});