Passing parameter to css :not selector
I have a function to hide all divs on the page except one div.
// hide all div exceept div1
function hideAllExcept()
{
$('div:not(#div1)').slideUp(800);
}
or
// hide all div exceept 'thisdiv'
function hideAllExcept()
{
$('div:not("#div1")').slideUp(800);
}
The above works fine (difference is first function doesn't have "" around #div1). However, I would like to pass a parameter in开发者_开发知识库 the hideAllExcept function to dynamically specify which div to not hide. So I changed the function to:
// hide all div exceept 'thisdiv'
function hideAllExcept(thisdiv)
{
$('div:not(thisdiv)').slideUp(800);
}
if i call the function using: hideAllExcept('#div1')
or hideAllExcept("#div1")
it doesn't work. It seems that $('div:not(thisdiv)') still selects all divs, it doesn't exclude thisdiv.
Any ideas? Many thanks
Change it to:
function hideAllExcept(thisdiv) {
$('div:not('+thisdiv+')').slideUp(800);
}
$('div').not(thisdiv).slideUp(800);
var divid='div:not('+thisdiv+')';
$(divid).slideUp(800);
精彩评论