R
R
Rokis2015-10-26 20:38:50
JavaScript
Rokis, 2015-10-26 20:38:50

What is wrong with this page turning code?

<div class='next1'>
<?php previous_post_link('%link', '<img src="#" width="45" height="35" alt="previous"  />'); ?>
</div>
<div class='prev1'>
<?php next_post_link('%link', '<img src="#" width="45" height="35" alt="Next" />') ; ?>
</div>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript"> 
$(document).keypress(function (e){ 
    if(e.keyCode == 37) // left arrow
    {
      
        $('.prev1').click();
    }
    else if(e.keyCode == 39)    // right arrow
    { 
        
        $('.next1').click();
    }
});
 </script>

Why does not work I can not understand, tell me please!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Scribblex, 2015-10-26
@Scribblex

$('.prev1').click(); –> $('.prev1').trigger('click');
$('.next1').click(); –> $('.next1').trigger('click');

I
Immortal_pony, 2015-10-26
@Immortal_pony

Where is the pagination code?

T
TM_ID, 2015-10-26
@TM_ID

What's wrong - terrible style code;
And, most likely, you need to bind an event to click on the desired elements.

$('.next1').bind('click', function(){
   // код
    return false;
});

D
Dmitry Kravchenko, 2015-10-27
@mydearfriend

If you are
trying to follow the link in this way, then this will not happen. Take the href attribute and put it in window.location

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question