motleydev
motleydev

Reputation: 3447

URL won't jump to hash with on(click, function) handler

I have this code:

$("a[data-action='sale'").on('click', function(){
    var target = $(this).attr('href');
    StateMaster.togglehorseFilters('for_sale');
});

Basically I am just trying to pre-fire a filter on my forum when a user clicks on it but still take them to the section of the page where the content is.

The hash jump works and then pre-filtering works but the page won't navigate to the hash when I try and piggyback on the click event.

Update:

Some requested to see the togglehorseFilters method:

togglehorseFilters: function(filter) {
    this.state.horseFilters[filter].value = !this.state.horseFilters[filter].value;
    this.emit('horse-search-term-visibility-change');
},

Upvotes: 0

Views: 40

Answers (1)

Mario Araque
Mario Araque

Reputation: 4572

You forget the ] in your selector.

$("a[data-action='sale']").on('click', function(){
  var target = $(this).attr('href');
  StateMaster.togglehorseFilters('for_sale');   
});

Upvotes: 1

Related Questions