Eggs
Eggs

Reputation: 345

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

I would like to dynamically update <h1> text to include <span></span> 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");

Upvotes: 3

Views: 49

Answers (2)

ameave
ameave

Reputation: 426

Just use $("h1").html() instead of $("h1").text().

Upvotes: 1

Arif
Arif

Reputation: 563

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");

Upvotes: 1

Related Questions