Link to home
Create AccountLog in
Avatar of EMB01
EMB01Flag for United States of America

asked on

jQuery Auto-Toggle Element

How do I use jQuery to change text from this:

This is my text

To this:

This is my text NOW

Every three seconds I want it to switch back and forth.
Avatar of Frozenice
Frozenice
Flag of Philippines image

hi,

HTML
<div id="reviews">
</div>

then jquery

var data = {
    reviews: [
        {
            review: "Excellent, 5 stars!"
        },
        {
            review: "Poor, 0 stars"
        },
        {
            review: "Beyond Excellent, 10 stars!"
        }
    ]
};

$.each(data.reviews,function(i,itemData){
    $('#reviews').append($('<p>').text('"'+itemData.review+'"'));
});

Open in new window



just change the review values and there you go... ;-)

enjoy.



br
ASKER CERTIFIED SOLUTION
Avatar of Frozenice
Frozenice
Flag of Philippines image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of EMB01

ASKER

Both are great answers, I upped to 500 so you would both get the full amount of points.

@Frozenice:  I was wondering why when I first run it does it seem to wait extra long, not just three seconds.  Also, the the anti-aliasing of the text is messed up on the first run only.  After it changes the text once, the fadeIn effect works perfectly.  Is there anyway to fix this?
Avatar of EMB01

ASKER

Also:

@Proculopsis:  Can you explain this syntax:

(tick&1 == 1)

I don't remember seeing this "&" ampersand used like this before.  Thanks in advance for your continued support.