質問

Iは、与えられたIDを持つすべてのdivを取得する必要がなく、jQueryの各機能のみ最初のものを得た。

例:

<div id="#historial">some html code</div>
<div id="#historial">some html code</div>
<div id="#historial">some html code</div>
<div id="#historial">some html code</div>

スクリプトます:

$("#historial").each(function() {
alert("one div");
});
私はアンカーを渡す場合は、id +アンカーは$を( "#ララA")ejが0

それは大丈夫に動作しています。

間違っているのですか?

BR

役に立ちましたか?

解決

あなただけのページ内の1つの要素の特定のIDを使用することができます。代わりにクラスを使用します:

<div class="historial">some html code</div>
<div class="historial">some html code</div>
<div class="historial">some html code</div>
<div class="historial">some html code</div>

$(".historial").each(function(e) {
  alert("one div");
});

他のヒント

アンIDは一意である必要があり、唯一の特定のIDを持つページ上の一つの要素があるはずです。

あなたがそれらのdiv要素のグループに代わり、使用「クラス」を必要とする場合。

<div class="historial">some html code</div>
<div class="historial">some html code</div>
<div class="historial">some html code</div>
<div class="historial">some html code</div>

改訂版のjQueryので、クラスで各DIVをルックアップするために「historal」は、このようになります:

$("div.historal").each(function() {
    alert($(this).text());    //Prints out the text contained in this DIV
});

また、#sidenote-、jQueryので使用されていないHTML markup-例えば、あなたが持っていた場合などのDIV

<div id="historal">stuff</div>

あなたはこのようなjQueryを使ってそれを見つけるだろう。

$("#historal")
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top