1

I have one textbox .the id is account_0__abc.the id will dynamically generted one.my question is how to select the id ending with __abc textboxes in a whole form using jquery?

User
  • 1,564
  • 9
  • 39
  • 62

3 Answers3

6

Try to use attribute ends with selector,

$('[id$="__abc"]')
Rajaprabhu Aravindasamy
  • 64,912
  • 15
  • 96
  • 124
1

If you want to make it more specific such as start with account_ and end with __abc then you can use:

$('[id^="account_"][id$="__abc"]')
Felix
  • 37,443
  • 7
  • 40
  • 55
1

There are various selectors in jQuery to identify elements based on a part of their id or names. You can specify the element type as well.

Here's an example:

$('input[id$="__abc"]')

This will grab <input> elements with id ending with __abc. Be careful though, if you got multiple ones that match this criteria, you'll end up with a collection. You can iterate through the collection and do stuff to them with a .each() like so:

$('input[id$="__abc"]').each(function(){
    // magic
});
domdomcodecode
  • 2,295
  • 4
  • 18
  • 27