-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
  • 5,377
  • 12
  • 50
  • 56
M. Galardi
  • 130
  • 1
  • 11

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
  • 62,450
  • 9
  • 45
  • 52