2

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!

1
  • it actually works for me, but I would say soyuka answer with the shorter selector and the preventDefault() should help you. Commented Mar 15, 2013 at 9:54

3 Answers 3

2

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

$("#problem-categories a").click(function(e) {
    e.preventDefault();
    console.log('pass');
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, used this along with $(document).ready(function() now it works!
1

This works good for me:

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

Comments

0

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

4 Comments

Its okay but find is faster in terms of performance i read somewhere.
faster then simple dom parsing like .scrollbox a ? I doubt that.
Well your answer just does that.
.find() can be faster in some specific circumstances, but it certainly isn't in this case. jsperf.com/jquery-find-selector-test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.