dorien dorien - 4 months ago 16
Ajax Question

Detect if a div with id including number is clicked

My site has x elements, with ids in this form:


whereby X is a number from 1 to ... (?).

What I want to do is, when somebody clicks one of these elements: get the number (X) of the respective .

$(document).ready(function () {
$("#viewer>").click(function () {
var number = x;


What's missing in this code is that viewer is not the full ID, but could be postpended with something. I want to store whatever is after the clicked div in number.


Try this,

 $("[id^='viewer_']").click(function () {
    var number =\d+$/)[0];