1

div のリンクを削除しようとしましたが、それは を使用して動作します。jsfiddleunwrap()で参照してください

今、私はウェブサイト上のリンクを削除するためにユーザースクリプトを実装したい( jsfiddleの例)が、うまくいきません。

タンパーモンキーを使用しています。これが私のユーザースクリプトです:

// ==UserScript==
// @name           Remove Link
// @include        http://jsfiddle.net/dv3Fm/2/embedded/result/
// ==/UserScript==

function addJQuery(callback) {
  var script = document.createElement("script");
  script.setAttribute("src", "http://code.jquery.com/jquery-1.9.1.js");
  script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "(" + callback.toString() + ")();";
    document.body.appendChild(script);
  }, false);
  document.body.appendChild(script);
}

// the guts of this userscript
function main() {
 $('.spoiler a > .smallfont').unwrap();
}

// load jQuery and execute the main function
addJQuery(main);

HTMLは次のとおりです。

<div class="spoiler">
    <!--I want remove link only -->
    <a href="http://www.domain.com" target="_blank">
        <div class="smallfont" id="bbcode_div"/>        
        </div>
    </a>  

</div>

<!--I want result such as : -->
 <div class="spoiler">
        <div class="smallfont" id="bbcode_div"/>        
        </div> 
</div>

私のユーザースクリプトは何が間違っていますか? ユーザースクリプトでアンラップjQueryを使用してリンクを削除するにはどうすればよいですか?

4

1 に答える 1