-2

I have this select:

<select id="987_country">

but I only know that the id ends with "country".

How I reference it (987_country) using:

$('#myIdName ')
Ivar
  • 6,138
  • 12
  • 49
  • 61
M. Galardi
  • 130
  • 2
  • 13

1 Answers1

3

Try with attributeEndsWith selector that

Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

$('[id$=country]')

console.log($('[id$=country]')[0].nodeName)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="987_country"></select>
Mamun
  • 66,969
  • 9
  • 47
  • 59