Dimitri Shukuroglou
Dimitri Shukuroglou

Reputation: 373

jquery selector and click event not working

I'm trying to get a jquery selector to work and give a response on console.log() on click however I cant seem to get it working.

Here is url

Code is:

$("div#tabs > div#problem-categories > div > div a").click(function() {
    console.log('pass');
});

any help would be very much appreciated!

Upvotes: 2

Views: 102

Answers (3)

Jai
Jai

Reputation: 74738

Use this:

$("div#problem-categories div.scrollbox").find('a').click(function(ev) {
   ev.preventDefault(); // <-----use this to prevent the jump 
   console.log('pass');
});

You have to traverse through this way. Get into problem-categories' scrollbox and find a in it and do the click.

FIND IN FIDDLE

Upvotes: 0

Sergio
Sergio

Reputation: 6948

This works good for me:

$("div#tabs > div#problem-categories > div > div a").on("click", function () {
    console.log('pass');
})

Upvotes: 1

soyuka
soyuka

Reputation: 9105

You need to prevent the link from beeing submitted, try this :

$("#problem-categories a").click(function(e) {
    e.preventDefault();
    console.log('pass');
});

Upvotes: 2

Related Questions