ユーザー選択に属するhtmlタグを知り、簡単に使用できるようにそれらを配列に入れる必要があるjavascriptアプリケーションを構築しています。
これを使用htmlTextすると、次のような文字列が得られました。
<h1><span style="color: rgb(102, 51, 153); font-weight: bold; text-decoration: underline;"><sub>test</sub></span></h1>
私は正規表現についてほとんど知識がなく、私が知っていることは私が望んでいることをしていないように見えるので、あなたの誰かがこの部分で私を助けてくれることを望んでいました.
では、上記の文字列を次の配列のように見せるにはどうすればよいでしょうか?
<h1>,
<span style="color: rgb(102, 51, 153); font-weight: bold; text-decoration: underline;">,
<sub>
これまでの私のコード(ただし、正しい軌道に乗っているかどうかはわかりません):
var fullhtml = SEOM_common.range.htmlText;//Get user selection + Surrounding html tags
var tags = fullhtml.split(SEOM_common.selected_value);//Split by user selection
var tags_arr = tags[0].match(/<(.+)>/);//Create array of tags
答えとコメントをありがとう。私は次のメソッドを構築することができました。これはまさに私が望むことを行います。
find_all_parents : function(selectRange,endNode){
   var nodes = [];
    var nodes_to_go = [];
    if(selectRange.commonAncestorContainer) nodes_to_go.push(selectRange.commonAncestorContainer.parentNode);//all browsers
        else nodes_to_go.push(selectRange.parentElement());//IE<9 browsers
        var node;
        while( (node=nodes_to_go.pop()) && node.tagName.toLowerCase() != endNode){
            if(node.nodeType === 1){ //only element nodes (tags)
                nodes.push(node);
            }
            nodes_to_go.push(node.parentNode);          
        }
        return nodes;
    }