0

I am having a problem with a script on this website I try to build. This is the script itself:

var id=0;
var cases=$('.cases').length;
$('#show').html($('#'+id).html());
setInterval(function() 
{
    $('#show').empty();
    if (id==cases-1)
        id=0;
    else
        id++;
    $('#show').html($('#'+id).html());
},5000);

this is the html code:

<div class="page">
    <br /><br /><headline>cases</headline><br /><br /><div id='case'></div><div class='content'><div id='show'></div><div id='column1'><div class='cases' id='0'><div class='short'><div id='cases-image'><img src='images/Sunset.jpg'/></div><div id='cases-info'><div id='cases-headline'>zxfbzsxdbfsdfh</div><cases-text>dfghsdfgsdfgsdfg</cases-text><div class='more' id=zxfbzsxdbfsdfh >להמשך קריאה...</div></div></div></div></div><div id='column2'><div class='cases' id='1'><div class='short'><div id='cases-image'><img src='images/גלריה1.bmp'/></div><div id='cases-info'><div id='cases-headline'>xbzsdfbsdf</div><cases-text>dafasdvasdvasdv</cases-text><div class='more' id=xbzsdfbsdf >להמשך קריאה...</div></div></div></div></div>            </div>
        <div id="footer">
</div>

It works in jsFiddle, but it doesn't work on my computer, it only shows the first case, the id in the script changes, but it doesn't get the html from the other cases... Can you help me?

1

2 Answers 2

1

Try using like this:

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript">

$(document).ready(function(){

    var id=0;
    var cases=$('.cases').length;
    $('#show').html($('#'+id).html());
    setInterval(function() 
    {
        $('#show').empty();
        if (id==cases-1)
            id=0;
        else
            id++;
        $('#show').html($('#'+id).html());
    },5000);

});
</script>

if your code worked in fiddle then it should work on your computer for sure if follow the conventions.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think that this is the problem, I'm using the latest version of jquery. thanks anyway
i mean the latest version of jquery on your local system
0

make sure

you have included the jQuery.js

you have wrapped the code inside the ready handler like

<script type="text/javascript">
$(function(){
 //your code
});
</script>

1 Comment

I did those things, that's not the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.