0

Can I put an image inside a span and give click event to the span using jQuery. Here it is not working in my code have any idea.

<span id="removeNewTime" class="removeTime">
    <img src="Images/close button.png" alt="close" />
</span>

jQuery code

<script>
    $(document).ready(function(){
        $(".removeTime").click(function(){
            alert("hello");
        });
    });
</script>
arulmr
  • 8,620
  • 9
  • 54
  • 69
Mansoor
  • 130
  • 1
  • 11

7 Answers7

1

It is work you might need to include jQuery, This post tell how to add jQuery on page.

Live Demo

$(document).ready(function(){
    $(".removeTime").click(function(){
     alert("hello");
    });
});​
Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
1

Either set your span's CSS to display:block; or replace the span with a <div>

Francis Kim
  • 4,235
  • 4
  • 36
  • 51
0

Make sure you have jquery library included before any doc ready function applied:

see the working fiddle:

http://jsfiddle.net/87Laj/

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js' type='text/javascript'></script>

<script>
   $(document).ready(function(){
     $(".removeTime").click(function(){
      alert("hello");
    });
  });
</script>
Jai
  • 74,255
  • 12
  • 74
  • 103
0

Make sure you have included jquery in the head section of your file. As the code is working fine.

For simplicity always use <script src="http://code.jquery.com/jquery-latest.js"></script>

This will ensure you always have the latest jquery file.

Sunil Mishra
  • 3,796
  • 1
  • 27
  • 40
0

May be the problem in jquery file, which is required to jquery code to be working.

Check the working jsfiddle

Small improvements to js code:

$(function() {
    $(".removeTime").on('click', function(){
         alert("hello");
    });
});​
Vladimir Starkov
  • 19,264
  • 8
  • 60
  • 114
0

This code is working Notice some points in your code

1) Don't forget to add latest jquery file like http://code.jquery.com/jquery-1.8.3.min.js to your code.

2) Download from http://jquery.com/download/

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
0

some times i do like this its dosnt work,

then i try this (if page dynamically chenged befor)

$(document).ready(function(){
    $(".removeTime").live("click",function(){
     alert("hello");
    });
});​ 
volvgang
  • 21
  • 4