Jean-philippe Emond
Jean-philippe Emond

Reputation: 1614

Select jquery input

It's a quick question for you,

I need to select Jquery element by type AND by name.

I know that we can do something like:

$('.form-control input[type=text]')....

but I need to select by name too..

do you have another way to do that unless using:

$('.form-control input[type=text]').each(function (){
   if($(this).attr('name') == 'search'){
        // this is my selector
   }
}

thank you

Upvotes: 2

Views: 123

Answers (5)

Fisherman
Fisherman

Reputation: 6131

$('.form-control input[type=\'text\']') or by name you can go

$('.form-control input[name=\'search\']')

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82251

use:

$('.form-control input[type=text][name="search"]').each(function (){
  //ohh yeah....this is my selector
}

Upvotes: 0

GautamD31
GautamD31

Reputation: 28763

Try like

$('.form-control input[type=text][name="search"]')

Upvotes: 1

Satpal
Satpal

Reputation: 133453

You should use Multiple Attribute Selector [name="value"][name2="value2"]

$('.form-control input[type=text][name="search"]')

Upvotes: 4

hsz
hsz

Reputation: 152294

Just try with:

$('.form-control input[type=text][name="search"]');

Upvotes: 2

Related Questions