jQuery hide with attributesStartsWith not working as expected [closed]
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 ]
精彩评论