jQueryで要素内に特定の文字列を含む文字列にリンクを追加したいがいい方法はないでしょうか?
例)
<table class="hoge"> <td class="fuga hoge">AAA</td> </table>
$(window).load(function(){ var hog = $("table.hoge td.fuga.hoge:contains('AAA')").html(); console.log(hog); });
consoleには「hog」が表示される
しかし
<table class="hoge"> <td class="fuga hoge">BBB<br>AAA</td> </table>
の場合NG
undefinedがかえる
やりたいこと
$(window).load(function(){ $("table.hoge td.fuga.hoge:contains('AAA')").html("<span><a href='hogefuga.com'>AAA</a></span>"); });
これで
AAAも
BBB<br>AAAも
<span><a href='hogefuga.com'>AAA</a></span>
BBB<br><span><a href='hogefuga.com'>AAA</a></span>
としたい
要素のして方法がわかりません
最終的に
AAAという文字列だけを<span><a href='hogefuga.com'>AAA</a></span>と書き換えたいです
ご教示ください
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。