tags:

views:

36

answers:

2

Attemping to use jQuery to find a button on a page "id=btn.ar" using . returns no matches even though the button is clearly on the page. Is there something about .* in jquery being different from other Regex's? The buttons exact id is btnClear so its obvious that btn.*ar should match $("id=btn.*ar")

+1  A: 

If you have an ID for an element use that as your first choice.

$("#btnClear")

If you are using the attribute filters you can match with

id contains "tnCl":

$("input[id*='tnCl']")

id starts with "btn":

$("input[id^='btn']")

id ends with "Clear":

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

You just need to find out which part of the id you want.

if you had a group of buttons with ids ['btn1', 'btn2', 'btn3'];

using the selector:

$("input[id^='btn']")

would grab all three of them.

Bobby Borszich
A: 

If I'm understanding you correctly, this should work:

$('button').filter(function() {
    return this.id.match(/^btn.*ar$/);
}).do_something();
tjko