JSFiddle - React, Tailwind, and code Playground
HTML
<div class="person person_3">
Sean
</div>
<p>Hello</p>
JavaScript
Element.Properties.person = {
get: function() {
var id = this.className.match(/person_(\d+)/)[1];
if(id) return Person.getById(id);
},
set: function(person) {
this
.addClass('person')
.addClass('person_'+person.id)
.set('html', person.name);
}
};
$('TestPerson').get('person'); // returns Person instance of ID 3.
$('OtherTest').set('person', new Person('John')); //turns the paragraph into a person
// <p class="person person_4">John</p>