How to open page use $(this) in JQuery?

Total Post:104

 1255  View(s)
Rate this:

Here I'm testing to see if I can click on the anchor with the id '#slide-1285' and log it to the console. It always says 'not testing'. I'm going to set up conditions for all id's so a user is redirected to the correct page. Something like this:

    $('#slidernavigation > a').on('click', function(e){
        if($ == $('#slide-1285')){
            window.location.href = http://webpage1;
        else if($ == $('#slide-1286')){
            window.location.href = "http://webpage2";
        else if($ == $('#slide-1287')){
            window.location.href = "http://webpage3";
        }       else($ == $('#slide-1288')){
        window.location.href = "http://webpage4";
    }               });

  1. Post:194

    Re: How to open page use $(this) in JQuery?

    To get the id of the element that was clicked, you can do:

    if ($(this).attr('id') === 'slide-1285') { window.location.href = "http://webpage1"; }

      Modified On Apr-05-2018 06:33:24 AM