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,644
  • 10
  • 40
  • 64

3 Answers3

6

Try to use attribute ends with selector,

$('[id$="__abc"]')
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
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,892
  • 8
  • 43
  • 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,355
  • 4
  • 19
  • 27