Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery array with next and previous buttons to scroll through entries
    primarykey
    data
    text
    <p>I'm sure this is a really basic question however I'm really new with jquery and I'm not sure how to do this. I did search through the forums and I found bits and pieces of helpful info but I just couldn't figure out how to put it all together. What I'm trying to create is a simple messages box where you can scroll through the messages with a "next" and "previous" button and also see which message # you're seeing. So basically it would be something like this in terms of design:</p> <hr> <p>$message_title ............. $message_# out of $total_#_messages</p> <p>$message_content</p> <p>[PREVIOUS BUTTON] - [NEXT BUTTON]</p> <hr> <p>Once you reach the last message, you just start over again so it would go msg_1 > msg_2 > msg_4 > msg_5 > msg_6 > msg_1 again and so forth.</p> <p>So I started with 2 arrays, one for the title and one for the message:</p> <pre><code>var array-title = [ "title 1","title 2","title 3" ]; var array-message = [ "message 1","message 2","message 3" ]; </code></pre> <p>I found a way to assign new text to an ID</p> <pre><code>$(document).ready(function(){ $("#btn1").click(function(){ $("#title-div").text("title 1"); $("#message-div").text("message 1"); }); }); </code></pre> <p>Where I have 2 divs with those specific IDs and it works great, however I'm not sure how to connect my array with my assign text code. I tried something like the following but it didn't quite work:</p> <pre><code>var i = 0; $(document).ready(function(){ while ( i &lt; array-title.length ) { $("#btn1").click(function(){ $("#title-div").text( array-title[ i ] ); $("#message-div").text( array-message[ i ] ); $("#message-number-div").text( i + 1 ); i++; }); } }); </code></pre> <p>I've tried a few other things but no luck. Can someone who has some free time please show me how to do this? If possible, please write the full code as that's where I'm having issues, putting the whole thing together. Thank you very much in advance for anyone kind enough to help me!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload