0

I have a pagination where I listen to the event ".pagination a" to change the page via ajax, inside a javascript class.

class Navigation {
 constructor(content, fetch_url, filter_id = null) {
    this.content = '#'+content;
    this.fetch_url = fetch_url;
    this.filter_id = filter_id;
 }

 paginate_event(selector_id = '.pagination a') {
    $(document).on('click', selector_id, (event) => {
        overlay(this.content);
        event.preventDefault();
        var params = window.location.search;
        var page = $(this).attr('href').split('page=')[1];
        this.fetch_data(params,page);
    });
 }
...
}

When I do the query I send the variables to the url so that if the site is updated, it stays on the same page, and if it has filters it keeps them.

The problem is in this line:

 var page = $(this).attr('href').split('page=')[1];

where $(this) it interprets it as a "this" of the class and not of the dom.

How can I make it interpret it as a "this" of the dom?

0 Answers0