开发者

jQuery hide with attributesStartsWith not working as expected [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I have a script that populates that hides and shows divs based on whether or not it contains a portion of an Id, then shows the div that contains the full, unique Id passed to the function. The function is as follows:

function showPlot(plotId) {
  // Hid开发者_Python百科e 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');
}

The problem is the .hide() function won't hide the specified divs as expected. I might not have the syntax right, but I'm pretty sure it's correct according to the API. Is there something else I'm missing? Help is appreciated.


You're missing the closing ].

$('div[id^="plot_"]')
             //   ^---------was missing


Change

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

to

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜