Eggs Eggs - 3 months ago 10
jQuery Question

how to use jquery to dynamically build a .text node that contains multiple <span>

I would like to dynamically update text to include tags.

My jsfiddle shows javascript that looks like this:

$("h1").text("Time Left:<span>" + padNum(glob.gameTimer) + "</span>Best:<span>" + padNum(glob.bestTime) + "</span>Reaction Time:<span>" + padNum(glob.reactionTime) + "</span");


Can someone show me how to insert the into the severals spots within my single tag?

Answer

Use html instead of text

$("h1").html("Time Left:<span>" + padNum(glob.gameTimer) + "</span>Best:<span>" + padNum(glob.bestTime) + "</span>Reaction Time:<span>" + padNum(glob.reactionTime) + "</span");