user6468101
user6468101

Reputation:

Document on click using selector

How to get the containing item using document on click.

var this_main = $(this);
     $(document).this_main.on('click', '.nav-circlepop a.prev', function(){
});

What am I doing wrong?

Upvotes: 0

Views: 516

Answers (4)

ameerabbas
ameerabbas

Reputation: 59

I don't exactly know that what you want to do, but it's for just idea for you

$('.nav-circlepop a.prev').click(function(){
     alert("now you can everything with this function");
});

Upvotes: 1

brk
brk

Reputation: 50326

You can use text method to grab the text .

Since you have not provided any HTML I presume the below HTML snippet is close to your code

HTML

<div class = "nav-circlepop">
<a class = "prev" href=""> Anchor tag text </a>
</div>

jQuery

$(document).on('click', '.nav-circlepop a.prev', function(event){
    event.preventDefault();
     document.write('<pre>'+$(this).text()+'</pre>')
});

Code Explanation

$(document).on('click', '.nav-circlepop a.prev',function(event){})

Any click event on document will be delegate to the target element.

Here the second parameter represent the target element.

where .nav-circlepop is a parent element and anchor tag a is child element. This anchor tag a has a class prev .So the target element is a.prev

Check this DEMO

Upvotes: 0

StackSlave
StackSlave

Reputation: 10617

You're just using excessive code:

$('.nav-circlepop a.prev').click(function(){
  console.log('worked');
});

Upvotes: 0

Anurag Deokar
Anurag Deokar

Reputation: 849

Use these one. The .on() method attaches event handlers to the currently selected set of elements in the jQuery object

 $(this_main).on('click', '.nav-circlepop a.prev', function () {
    });

Upvotes: 0

Related Questions