tags:

views:

138

answers:

1

I have Attribute Filter like this one $(’input[name="email"]‘);

I want to create a function with parameter, which would contain name of attribute..something like this:

function test(id_new){
     var var_name = $("input[name='"+id_new+"']:checked").val();
    alert(var_name);
}

but this code is not working, any solutions?

+2  A: 

Which version of jQuery are you using? I'll assume 1.3.

Try removing the single quotes in the attribute selector:

function test(id_new){
     var var_name = $("input[name="+id_new+"]:checked").val();
    alert(var_name);
}
John Rasch
From JQuery Docs: Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again. So Vaske's syntax in that respect should be correct
AdamB
Right, at first I was assuming he was using that syntax for an older version
John Rasch
Noup I'm using jQuery 1.3.
vaske
That's pretty odd because there's really no reason that adding single quotes would cause a problem. Curious indeed...
KyleFarris