0

In this fiddle, http://jsfiddle.net/5L8Q8/52/ if you click the black box, it randomly selects either "ONE" or "TWO" from an array and assigns that value to "ran."

There are also two divs on the page "ONE" or "TWO" with text content in each. These divs are unrelated to the values selected from the array

Depending on the value assigned to ran, I want to express the text contents of div "ONE" or "TWO" inside div "result"...

I was playing around with something like this below but made no progress

$('#result').html(function() {
  //some function to put contents of either div ONE or TWO (depending on ran) inside of #result
});
1
  • Your fiddle code needs some tidying up... Commented Jul 22, 2011 at 2:00

3 Answers 3

5

http://jsfiddle.net/5L8Q8/57/

$("#button").click(function() {
    ran = getRandom(myArray, true);

    $('#result').html($("#" + ran).html()); 
});
Sign up to request clarification or add additional context in comments.

2 Comments

thank you that's very clever. I have to wait 8 minutes to accept your answer.
When I was done I actually noticed when I hit update that the fiddle had grown like 5 revisions since I started and I was toast
0

Like this: http://jsfiddle.net/Paulpro/5L8Q8/54/

$('#result').html($('#'+ran).html());

Comments

0

Here it is:

$('#button').click(function() { 
  ran = getRandom(myArray, true); 
  $('#result').html($('#'+ran).html());
});

http://jsfiddle.net/5L8Q8/62/

Comments

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.