JQuery selector in variable

Posted by nagut on Stack Overflow See other posts from Stack Overflow or by nagut
Published on 2010-05-16T10:43:20Z Indexed on 2010/05/16 10:50 UTC
Read the original article Hit count: 267

Filed under:
|
|
|

I wanted to ask about using selector from a variable

first I have:

function check()
{
  $('.info input, .info select').each(function(n, element){
     if ($(element).val()=='')
     alert('empty');
  });
}

and called it in

$('input')change(check);

and they worked fine.

But now I want to pass some value to the function to make it dynamic, like

$('input')change(check('.info'));

and changed the function to

function check(sel) {   
     $(sel +' input, '+ sel + ' select').each(function(n, element){
     if ($(element).val()=='')
     alert('empty');   
  }); 
 }

but it doesn't work. Any help please.. Thanks,

nagut

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about selector