javascript - Randomly rotate content of a span -


i'm trying change <span> of text 1 of 7 chunks of text. i've found tutorial can me using javascript below, however, relies on selections being kept in <ul>. don't think can that, because need changed text appear within pre-existing paragraph.

i'm thinking there might way give span id, , then, within javascript, set different options content be.

i want change happen randomly page loads or refreshed, nothing complicated having happen on user input or on timer.

below script found on tutorial, maybe it's case of simple amendment. i'm such newbie, though, don't know start unless it's spelt out.

<script type="text/javascript">  this.randomtip = function(){     var length = $("#tips li").length;     var ran = math.floor(math.random()*length) + 1;     $("#tips li:nth-child(" + ran + ")").show(); };  $(document).ready(function(){        randomtip(); });  </script> 

something works:

javascript

<script type="text/javascript">     $(document).ready( function() {          // hide of tips         $('#tips').children('.tip').hide();          // randomly select 1 tip show         var length = $("#tips .tip").length;             // **edit **         // code buggy!         //var ran = math.floor(math.random()*length) + 1;         //$("#tips .tip:nth-child(" + ran + ")").show();         // use instead:         var ran = math.floor((math.random()*length));         $('#tips > .tip:eq('+ran+')').show();     }); </script> 

html

<p id="tips">     <strong>random tip: </strong>     <span class="tip">this tip 1.</span>     <span class="tip">this tip 2.</span>     <span class="tip">this tip 3.</span>     <span class="tip">this tip 4.</span>     <span class="tip">this tip 5.</span>     <span class="tip">this tip 6.</span>     <span class="tip">this tip 7.</span> </p> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -