Home > DeveloperSection > Forums > How to open page use $(this) in JQuery?
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    October-04-2014 4:11 AM

 JQuery JavaScript  JQuery 
Ratings:


 1 Reply(s)
 698  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:

<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>



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-04-2014 4:17 AM

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

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


Don't want to miss updates? Please click the below button!

Follow MindStick