JSFiddle - React, Tailwind, and code Playground

HTML

<div id="id-2"><p class="msg">The message</p></div>          
<a href="javascript:" class="bookmarked has-tooltip id-2" data-title="Add to Favorites"id="2">Add</a>

JavaScript

$('.bookmarked').click(function(){		//execute this function when the link was clicked
    
    // CALL OF AJAX  -> data
    // {
    
    var classes = $(this).attr('class');		//fetch all classes of the clicked item (this is a string)
    //alert('The classes: '+classes);
    var classarray = classes.split(' ');		//split the string into it parts seperated by "blank"
    $.each(classarray, function(index, item){		// execute this for every subpart
        //alert(index+' '+item);
        if(index==2)			// since the third (better: use regexp) subpart stores the id-information...
        {
            //alert(item);
            
            $('#'+item).html('<p>NewText</p>');		// ...do something with it. use the data of ajax as well. 
        }
    });
    
    //}
});