私は以下のjQueryコードを持っています。このような2つのイベントリスナーを書いていますか?次のコードは、an.errorjQueryコードが 'Object expected'エラーを返します
$(document).ready(function() {
$('tr').hover(
function() {
$(this).css('background-color', '#FFFF99');
$(this).contents('td').css({
'border': '1px solid red',
'border-left': 'none',
'border-right': 'none'
});
$(this).contents('td:first').css('border-left', '1px solid red');
$(this).contents('td:last').css('border-right', '1px solid red');
});
$('#radioButtonImageSourceContainerId input:radio').click(function() {
if ($(this).val() === 'fromFile') {
addVisibility("from-file");
removeVisibility("from-url");
}
else if ($(this).val() === 'fromUrl') {
removeVisibility("from-file");
addVisibility("from-url");
}
})
});
他の2つの機能は、あなたが最初の要素を発見したことを確認する
function addVisibility(elemId) {
document.getElementById(elemId).style.display = "";
if (document.getElementById(elemId).style.visibility == "hidden") {
document.getElementById(elemId).style.visibility = "visible";
}
}
function removeVisibility(elemId) {
document.getElementById(elemId).style.display = "";
if (document.getElementById(elemId).style.visibility == "visible") {
document.getElementById(elemId).style.visibility = "hidden";
}
}
'find()'は直接の子だけを見るのではなく、再帰的に検索します。 'children()'はここに行く方法ですが、DOMの1つ下のレベルにしかなりません。 –
@Cory:ネストしたテーブルが見つからない限り、はいです。 OPの 'contents()'(マークアップの不備)の誤用を考えると、私は確信が持てませんでした。しかし、はい、ほとんどの場合、「子供」が意図されています。 – RightSaidFred
... 'getElementsByTagName'を使うことができれば、実際にはもっと速くなるかもしれないので、' find() 'を使う方が好きな人もいます。最終的に 'var tds = $(this).find( 'td')...とする必要があります。 tds.first()...; * – RightSaidFred