How to get html element by name in jquery?

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

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

how can i achieve this

Thanks in Advance :)

+4
source share
3 answers

Store the names in the array and check if the current attribute is namein the array.

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

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

try it

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

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

I thought you need to check if the entire complete string matches

+2
source
$("input").is("[name=listItem], [name="GrdFromDateTime"]...)
+1
source

Source: https://habr.com/ru/post/1621411/


All Articles