dorien dorien - 1 year ago 89
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.

Answer Source

Try this,

 $("[id^='viewer_']").click(function () {
    var number =\d+$/)[0];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download