私は動的にjs関数でヘッダーの下にURLを変更しようとしています。残念ながら私は簡単な部分に積み重ねています。JSのヘッダーの下のURLの変更
はlinkによると、私は...その問題を解決するために私のコードの
簡易版試してみました:
<div class="details">
<h1 id="title">Old title</h1>
<h3 id="author">
<a id="aId" href="https://www.google.pl/">Old author</a>
</h3>
</div>
をスクリプト:
var title = $("#title");// the id of the heading
var author = $("#author");// id of author
title.text("New title");
author.text("New author");
var a = document.getElementById('aId');
a.href = "bing.com"
問題は、著者が今はないということですクリック可能。私たちを手伝ってくれますか?
EDIT:あなたの助けを
ありがとう! ソリューション:
var title = $("#title");// the id of the heading
var author = $("#author a");// id of author
title.text("New title");
author.text("New author");
author.attr("href", "http://bing.com")
ありがとうございました。それは働いていますが、本当に2つの識別子が必要ですか? '#author a'や 'ald'のようなものですか?よりエレガントな方法はありますか? – Misiek777
もっとエレガントな方法がありますが、変更を最小限に抑えようとしました。 'author.text(" New author ")。attr(" href "、" http://bing.com ");'を実行して、すべての変更を1行で行うことができます。 –