Reputation: 41919
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
});
Upvotes: 0
Views: 89
Reputation: 15390
Here it is:
$('#button').click(function() {
ran = getRandom(myArray, true);
$('#result').html($('#'+ran).html());
});
Upvotes: 0
Reputation: 141839
Like this: http://jsfiddle.net/Paulpro/5L8Q8/54/
$('#result').html($('#'+ran).html());
Upvotes: 0
Reputation: 78630
$("#button").click(function() {
ran = getRandom(myArray, true);
$('#result').html($("#" + ran).html());
});
Upvotes: 5