var gethtml = $("#topmenu > li.l89 a").text().split(' ')[1].replaceWith('Any World');
上記のように使用してもテキストは変化しませんreplaceWith
。
var gethtml = $("#topmenu > li.l89 a").text().split(' ')[1].replaceWith('Any World');
上記のように使用してもテキストは変化しませんreplaceWith
。
.text()を呼び出すと、jQueryオブジェクトではなく、プレーンな文字列で作業することになります。あなたはこのようにそれを行うことができます...
var text = $("#topmenu > li.l89 a").text()
, textParts = text.split(' ');
textParts[1] = "Any world";
console.log('New text', textParts.join(" "));
手順を確認できるように、長いバージョンを作成しました。必要に応じて、1行で実行できますが、もうあまり読みやすくありません。