2つのボタンと画像を取得しました。いずれかのボタンを押すたびに、画像がフェードアウトします。このデモのように: http://jsfiddle.net/5wBuV/6/
問題は、これが最初のボタンでのみ機能し、2 番目のボタンが機能しないことです。単純な間違いかもしれませんが、私は本当にJSを始めています。
$("#clickedButton").click( function() {
$("#hide").fadeOut("slow");
});
2つのボタンと画像を取得しました。いずれかのボタンを押すたびに、画像がフェードアウトします。このデモのように: http://jsfiddle.net/5wBuV/6/
問題は、これが最初のボタンでのみ機能し、2 番目のボタンが機能しないことです。単純な間違いかもしれませんが、私は本当にJSを始めています。
$("#clickedButton").click( function() {
$("#hide").fadeOut("slow");
});
id of an element must be unique, if you use ID selector jQuery will return only the first element with the id.
In your case if you want to add same event handler to a set of elements, you can use a common class attribute and then use class-selector
<!-- The button -->
<a href="#" class = 'clickedButton'>
<img src="http://www.kwvs.pepperdine.edu/playbutton.png" />
</a>
<a href="#" class = 'clickedButton'>
<img src="http://www.kwvs.pepperdine.edu/playbutton.png" />
</a>
then
$(".clickedButton").click( function() {
$("#hide").fadeOut("slow");
});
Demo: Fiddle