On Feb 16, 9:27 am, Klaus Hartl <klaus.ha...@googlemail.com> wrote:
> The jQuery way:
>
> $('#state').filter('select').doSomething();

Using filter is a bit inefficient when there is zero or one element,
it seems that if a selector is to be used and the function is to run
only if a select is found, then:

  var obj = $('select#state');
  if (obj.size()( {
    // found a select with an id of state
  }

To branch depending on whether the element is a select or an input.

  $('#state').each(function(i){
    var tag = this.tagName.toLowerCase();
    if (tag == 'select') {
      // do something with the select
    } else if (tag == 'input') {
      // do something else with the input
    }
  });


--
Rob

Reply via email to