Question

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");
    });
});
Was it helpful?

Solution

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.

OTHER TIPS

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

Because it has a default click function you should try

$(".que_issue").click(function(event) {
    event.preventDefault();
    alert("Jumbo");
});

Use this,

$(document).on('click', '.cancel_logo', function(){
    alert("Jumbo");
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top