This function is used for <iframe> HTML element unwrapping. Most of the lines are repeated. How can I simplify this function?<span id=pc1430828456801 class=optins>new insert text</span><span id=pc1430828456801 class=optdel>perturbative</span>I have the same ID for both classes. I want to remove tag and innerhtml for the class=options. But in class='optdel' I need to remove the surrounding tag only and retain text. How can I do this in the same function if both element ids are the same?function Undotext() {    try{        var checkopttag = $('#main_iframe')[0].contentWindow.document.getElementById(holder).parentElement.className.startsWith(opt);        if(checkopttag === true){            var r = confirm(Please confirm UNDO correction);        if(r === true){            var undoclassname = $('#main_iframe')[0].contentWindow.document.getElementById(holder).parentElement.className;            var undoidname = $('#main_iframe')[0].contentWindow.document.getElementById(holder).parentElement.id;            var elements = $('#main_iframe')[0].contentWindow.document.all(undoidname);            if(undoclassname === optins || undoclassname === optdel){                    if(elements.length === 2){                      for (var i=0, im=elements.length; im>i; i++) {                           $('iframe').contents().find(# + undoidname).remove();                          var $newText = $('iframe').contents().find(# + undoidname);                          $newText.replaceWith( $newText.text() );                            }                    } else if(elements.length === undefined && elements.className === optins) {                      $('iframe').contents().find(# + undoidname).remove();                    } else if(elements.length === undefined && elements.className === optdel) {                      var $newText = $('iframe').contents().find(# + undoidname);                      $newText.replaceWith( $newText.text() );                    }                } else {                            var $newText = $('iframe').contents().find(# + undoidname);                    $newText.replaceWith($newText.text());                }        }        } else {            alert(Undo Not possible Here);        }    }catch(e){        alert(Catch error: +e);    }}
iframe HTML element unwrap
javascript;jquery