0

Possible Duplicate:
jQuery Selector: Id Ends With?

Suppose I have controls called ctl00_mstPartBase_lblTopPager and ctl00_mstPartBase_lblBottomPager.

These controls have many hyperlinks. I want to bind a click event for those hyperlinks. I have tried:

$('#lblTopPager #lblBottomPager a').click(function (e) {
        alert("click occured");
        e.preventDefault();

});

However the above code does not work because my control name is ctl00_mstPartBase_lblTopPager

How could I bind a click event with those hyperlinks when the parent control's name is not fixed, the only fixed parts are lblTopPager and lblBottomPager.

What code should I write such that a single click binding will work for all the hyperlinks in the two containers. Please help. Thanks

I did it in this way

    $('[id$=lblTopPager] a, [id$=lblBottomPager] a').live("click", function (e) {
        alert($(this).text() + ' this is my anchor text ');
        e.preventDefault();
    });

$(document).ready(function () { $('[id*=btnOk]').live("click", function () {

});

});

Community
  • 1
  • 1
Thomas
  • 33,544
  • 126
  • 357
  • 626

1 Answers1

3

This should select all the elements with id ending in lblTopPager

$("[id$=lblTopPager]")

and this should select all the a elements which parents id ends in lblTopPager

$("[id$=lblTopPager] a")
MJC
  • 3,871
  • 4
  • 23
  • 34