javascript - Add <span> to innerHTML with value -


based off thread: using css stylesheet javascript .innerhtml

to stylize innerhtml such this:

document.getelementbyid("id").innerhtml = "this error"; 

all need this:

document.getelementbyid('error-message').innerhtml = "<span class='error'>my  error</span>"; 

but if have value? how apply tag this:

document.getelementbyid('ptext').innerhtml = "you clicked: " + value; 

innerhtml string that's converted / interpreted html, long add tags around value, it'll work:

document.getelementbyid('ptext').innerhtml = "<span>you clicked: " + value + "</span>"; 

alternatively, add span html directly, , set innerhtml of span "you clicked :" + value in js, bit cleaner.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -