Retrieve attribute value of html element within var string containing HTML, via jQuery

HTML

hello

JavaScript

// This value of var selectionFromTinyMCE is an example
    // of what parent.tinyMCE.activeEditor.selection.getContent(); returns to you
    var selectionFromTinyMCE = 'sit our <a href="../forum/index.php">community forum</a>! We also';
    
    // Here we take the string returned by TinyMCE, wrap it with a span tag,
    // and pass it into a jQuery. This forces jQuery to evaluate the string as HTML!
    var $jStr = $("<span>"+selectionFromTinyMCE+"</span>");
    
    // You then create new variable and store the value of the href attribute
    // of the <a> element from within your string.
    var hrefValueFromTinyMCEselection = $jStr.find("a").attr("href");
    
    // Check the console to see the result below, outputted as a string
    console.log( hrefValueFromTinyMCEselection );