var board = $('#board'); function room_2() { board.html("Once upon a time, Keith Paul was famished. He couldn't decide what to have."); var link = $('<a href="#">Fancy Lunch</a>'); link.click(room_3); board.append(link); var link = $('<a href="#">Regular Lunch</a>'); link.click(room_4); board.append(link); } function start() { var link = $('<a href="#">Keith Paul</a>'); link.click(room_2); board.append(link); } function room_3() { board.html("He could have Pho in the new Bluewall."); makelink("But he doesn't know how to use chopsticks. So maybe he should have a regular lunch.", room_4); } function room_4() { board.html("He could have a burger and fries."); makelink("He ate this and was happy. Want to play again?", room_2); } function makelink(text, action) { var link = $('<a href="#">' + text + '</a>'); link.click(action); board.append(link); } start();
<div id="board">Loading...</div>
#board { border: 3px dashed #0033cc; padding: 10px; } #board a { display: block; padding-top: 5px; }