I would like to build in error handling for this piece of javascript so that if #next doesnt exist that it will do something else. Currently when it doesnt exist it just gives me an undefined in the url or an error page. Please let me know what i can do here. thanks
<script>
$(document).on("pageinit",function(){
var pathname = $(location).attr('href');
var leva = $('#next').attr("href");
var prava = $('#prev').attr("href");
$("body").on("swiperight",function(){
<!--alert("You swiped right!");-->
location.href=prava;
});
$("body").on("swipeleft",function(){
<!--alert("You swiped left!");-->
location.href=leva;
});
});
</script>
$('#next').length
to see if any elements were selected. Or just check ifleva
isundefined
.if(leva) { location.href=leva } else { /* do something else */ }