2011-06-17 15 views
0

私は、Idの一部を含むかどうかに基づいてdivを表示して表示するスクリプトを作成し、その関数に渡された一意の完全IDを含むdivを表示します。関数は次のようになります:jQuery hidden with attributesStarts期待どおりに動作しない

function showPlot(plotId) { 
    // Hide all plots by switching them to a class 
    $('div[id^="plot_"').hide(); //<--Won't hide the divs matching that portion of the Id 
    // Show the selected plot by changing it's class 
    $('#' + plotId).show('fast'); 
} 

問題は、.hide()関数が指定されたdivを期待どおりに非表示にしないことです。私は構文の権利を持っていない可能性がありますが、私はそれがAPIによれば正しいことを確信しています。私は行方不明の何か他にありますか?ヘルプは高く評価されます。

$('div[id^="plot_"]').hide(); // you were missing the last ] 
+0

関数が正しく呼び出されていますか? –

答えて

3

+0

'plot_'の周りの引用符で動作しますか? jQueryは 'id =" "plot _" "'で要素を探します。内側の引用符は実際のIDの一部です。たぶんではない –

+1

@Connor:いいえ、jQueryはそのIDを検索しません。実際には引用符は必須です:http://api.jquery.com/attribute-equals-selector/ –

+0

@Connor:そうですね。引用符は、実際には、さまざまな*属性セレクタ*の値に対して必須です。 – user113716

1

変更

$('div[id^="plot_"').hide(); 

あなたは決算]を逃しています。

$('div[id^="plot_"]') 
      // ^---------was missing 
関連する問題