HOW TO OPEN PAGE USE $(THIS) IN JQUERY?

marcel ethan

Total Post:105

Points:735
Posted by  marcel ethan
 960  View(s)
Ratings:
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:

<script>

    $('#slidernavigation > a').on('click', function(e){

        e.preventDefault();

        $(this).showSlide();

        if($a.id == $('#slide-1285')){

            window.location.href = http://webpage1;

        }

        else if($a.id == $('#slide-1286')){

            window.location.href = "http://webpage2";

        }          

        else if($a.id == $('#slide-1287')){

            window.location.href = "http://webpage3";

        }  

    else($a.id == $('#slide-1288')){

        window.location.href = "http://webpage4";

    }          

    });

</script>

  1. Kamlakar Singh

    Post:194

    Points:1396
    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"; }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!