I have the following code which works fine:
$(function mvp() {
var theMvp = ['#mvpWtd', '#mvpStd'];
$.each(theMvp, function (index, value) {
$(value + ' .budTySales').hide();
$(value + ' .lySales').hide();
$(value + ' .budReceipts').hide();
$(value + ' .lyReceipts').hide();
});
})
According to jquery documentation I should be able to pass multiple elements in followed by a comma instead of doing it line by line (less code too!). I tried changing my code to the below but it fails...
$(function mvp() {
var theMvp = ['#mvpWtd', '#mvpStd'];
$.each(theMvp, function (index, value) {
$(value + ' .budTySales',value + ' .lySales',value + ' .budReceipts',value + ' .lyReceipts').hide();
});
})
This line:
$(value + ' .budTySales',value + ' .lySales',value + ' .budReceipts',value + ' .lyReceipts').hide();
should be:
$(value + ' .budTySales,' + value + ' .lySales,' + value + ' .budReceipts,' + value + ' .lyReceipts').hide();
Notice that the commas are inside the quotes. This is because jQuery expects a single parameter to be passed into it, not multiple, which is what you were doing.
As stated in the comments, comma should be part of the string.
$(value + ' .budTySales, ' + value + ' .lySales, ' + value + ' .budReceipts, '+ value + ' .lyReceipts').hide(); should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With