Search code examples
jquerygridviewwildcardhandle

JQuery property selector with Wildcard


I am trying to shift the Row index after clicking my Up/Down arrows inside a gridview, Unfortunately when I enter my Jquery it only seems to be getting a handle on 1 of the gridviews inside my Repeater.

The ID I am passing to get a handle on the row is:

$('#Repeater1_ctl16_MeetingSumaryGridview1 a.move').click(function () {

The problem is that the 'ctl16' changes depending on which gridview I have selected the arrows from, I would like to be able to put a wildcard in here that will get a handle on the gridview for the Arrows I have selected.

Below is my JQuery Code:

$(document).ready(function () {
   $('#Repeater1_ctl16_MeetingSumaryGridview1 a.move').click(function () {
      var row = $(this).closest('tr');
      if ($(this).hasClass('up')) {
          var headrChck = row.prev()
          if (headrChck[0].cells['1'].tagName != 'TH') {
              row.prev().before(row);
          }
      }
      else {
          row.next().after(row);
      }
  });
})

I have tried many things that I have found online but all the Wildcards i seem to use do not get a handle.

I was wondering if I could get some Help/Advice on this, Anything is appreciated, Thank You in advance.


Solution

  • If you look at the documentation you will find that ^ and $ are wildcards in jQuery.

    I think in your case it should look something like this:

    $("[id^=Repeater1]").click(function () {
          var row = $(this).closest('tr');
          if ($(this).hasClass('up')) {
              var headrChck = row.prev()
              if (headrChck[0].cells['1'].tagName != 'TH') {
                  row.prev().before(row);
              }
          }
          else {
              row.next().after(row);
          }
      });
    

    TL;DR;

    • use * for contains

    • use ^ for starts with

    • use $ for end with

    Beware that the comparison is case sensitive.