jquery - get id attr of (this)

142 Views Asked by At

An anchor tag similar to this is clicked.

<a href="go.php?id=3aaa">Click Me</a>

$(this)[0] contains a string similar to http://localhost/www/go.php?3aaa

I wish to strip the "3" and "aaa" (values change according to what is clicked) into their own variables and test for their values.

1

There are 1 best solutions below

2
On BEST ANSWER

Try this:

var match = $(this)[0].match(/\?(\d{1,})(\w*)/);

then match[1] has the digit (3 like above) and match[2] has the string (aaa like above);