Retrieve parent node from selection (range) in Gecko and Webkit

前端 未结 3 1884
北恋
北恋 2021-02-09 20:37

I am trying to add an attribute when using a wysiwyg editor that uses \"createLink\" command. I thought it would be trivial to get back the node that is created after the browse

3条回答
  •  庸人自扰
    2021-02-09 20:49

    It's a hacky workaround, but should work unless somebody makes two identical links.

    this.getSelection() seems to get the same in both needed browser, so:

    var link=prompt('gimme link');
    
    //add the thing
    
    var text=this.getSelection();
    
    var whatYouNeed=$('a:contains("'+text+'")[href="'+link+'"');
    

提交回复
热议问题