R K Sharma
R K Sharma

Reputation: 855

how to get html element by name in jquery?

I know the selector used for name is $('input[name=xyz]') but what if I have a condition ex.

 if (input.is("[name=listItem,GrdFromDateTime,GrdToDateTime,GrdRemarks]"))

how can I achieve this?

Thanks in Advance :)

Upvotes: 4

Views: 71

Answers (3)

gurvinder372
gurvinder372

Reputation: 68393

try this

var validValues = "listItem,GrdFromDateTime,GrdToDateTime,GrdRemarks";

if ( validValues.split(",").indexOf( input.attr("name") !== -1 )

I thought you were wanted to check if all complete string is matching

Upvotes: 2

Tushar
Tushar

Reputation: 87203

Keep the names in an array and check if the current input name attribute is in the array.

var names = ["listItem", "GrdFromDateTime", "GrdToDateTime", "GrdRemarks"];

if(names.indexOf(input.attr('name')) !== -1) {

Upvotes: 8

void
void

Reputation: 36703

$("input").is("[name=listItem], [name="GrdFromDateTime"]...)

Upvotes: 1

Related Questions