1

I want the following structure

<div class="test">
<div class="test1"> 
</div>
</div>

I am trying to right down click event on test1

$(".test .test1").click(function()
{

 });

but it's not binding.

Any help?

3
  • 1
    is that your complete code? Commented Mar 13, 2014 at 15:44
  • Are the elements dynamically added to the DOM? Also is it right click you want or a normal click? Commented Mar 13, 2014 at 15:45
  • added how I added to jquery now edited to with function Commented Mar 13, 2014 at 15:46

1 Answer 1

1

You need:

$(".test .test1").click(function() {
     // Your code to handle when .test1 inside .test is clicked
});

or if you want to trigger click event on this element, then you can use .trigger():

$(".test .test1").trigger('click');

Also, remember to add your code inside DOM ready handler:

$(function() {
    $(".test .test1").click(function() {
         // Your code here
    });
});

If your element are added dynamically to the DOM, you need to use event delegation:

$('body').on('click', '.test .test1' , function() {
    // Your code here
});
Sign up to request clarification or add additional context in comments.

1 Comment

Did you try event delegation? check my answer.

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.