rcsnooks rcsnooks - 9 months ago 39
jQuery Question

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? Thanks!


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


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


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

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