-1

I'm having a hyperlink and upon clicking on it I want to show tha alert pop-up but it's not working. Can anyone tell me where I'm doing wrong? jsfiddle

Following is my HTML Code:

<a href="#" class="que_issue">QUE414</a>

Following is my jQuery Code:

$(document).ready(function(){
    $(".que_issue").click(function() {
       alert("Jumbo");
    });
});
elixenide
  • 44,308
  • 16
  • 74
  • 100
PHPLover
  • 1
  • 51
  • 158
  • 311

4 Answers4

2

You can use e.preventDefault() to prevent default action of your anchor which will reload the page

$(document).ready(function () {
    $(".que_issue").click(function (e) {
        e.preventDefault()
        alert("Jumbo");
    });
});

Updated Fiddle


Edit: Actually, you're missing jQuery in your jsFiddle. In the other hand, you've used # for your anchor so there's no need to use e.preventDefault() here but it's a good habit to use e.preventDefault() when you want to prevent a default action from happening such as using AJAX to submit a form.

Felix
  • 37,892
  • 8
  • 43
  • 55
2

your code is ok. just include the JQuery library from the left panel in jsfiddle

Linga
  • 10,379
  • 10
  • 52
  • 104
kp singh
  • 1,430
  • 8
  • 21
1

Because it has a default click function you should try

$(".que_issue").click(function(event) {
    event.preventDefault();
    alert("Jumbo");
});
Linga
  • 10,379
  • 10
  • 52
  • 104
Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

Use this,

$(document).on('click', '.cancel_logo', function(){
    alert("Jumbo");
});
Linga
  • 10,379
  • 10
  • 52
  • 104
HB Kautil
  • 267
  • 1
  • 6