Refresh and replace content in a div using JQuery?

You were just about there. A few changes are needed.

You were just about there. A few changes are needed. First add a css rule to hide your divs. .

Newjobz{ display: none; } Then change your javascript like so: function randomFromTo(from, to) { return Math. Floor(Math.random() * (to - from + 1) + from); } function displayRandomJob() { var r = randomFromTo(1, $('div. Newjobz').

Length); $('div. Newjobz').hide(). Eq(r - 1).show(); } $(document).

Ready(function() { displayRandomJob(); $('#jobchanger'). Click(function() { displayRandomJob(); }); }); jsFiddle.

This works great thank you! Much appreciated everyone! – The Fragile Machine Jun 29 at 21:50 You're welcome.

You can remove those console. Log lines. They were just for debugging and I forgot to removed them before I posted the answer.

– Craig M Jun 29 at 21:51.

How about something like this: $("#buttonId"). Click(function() { var numElements = $(". Newjobz").

Length; var randomContent = $(". Newjobz"). Eq(Math.

Floor(Math.random() * numElements)).html(); $("#divToChange"). Html(randomContent); }); You could shorten this by getting rid of the variable declarations and doing it all on one long line, but I broke it up to make it more readable. That will take the HTML from a random div with class "newjobz" and overwrite the HTML of the div with id "divToChange" with it.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions