views:

119

answers:

2

Hi All,

In our application we are using set of images as slides. If we click one image we want to get the id of the in the same page. i have tried by using the following code.

code: HTML:

<a id="100" href="#"> <img scr="..."/> </a>
...

JQUERY code:

$("div.alb a").click(function() {

        });

Problem:

Without href="#" the click event is not working.

I want to get the id by clicking the image without using server control.

Without using server control is it possible to achieve this task. 

Geetha.

+2  A: 

html:

<img src="..." id="i100"/>

js (jquery):

$('img[id]').click(function(){
  var my_id = $(this).attr('id');
  return false;
});

otherwise, if you cant modify your html-code just add 'return false' to prevent redirect.

Skay
+1 for not including the surplus useless anchor tags in this example.
Sohnee
A: 

It seems to work for me without using herf.

You can check it out here.

http://jsbin.com/uroke

I can't get a image to show up when using jsbin not sure why though.

$(function()
  {
      $("a").click(function()
      {
          var test = $(this).attr('id');
          alert(test);
      });
  });
chobo2