2

i have javascript jquery that looks like this:

var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + userInput);

i would like to know how i can include html into the text something like this:

var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + '<b>' + userInput + </b>);

how do i inject html into the javascript?

2
  • did u try changing the text() to html() ? Commented Oct 11, 2011 at 17:51
  • 1
    Your </b> isn't wrapped in single quotes... Commented Oct 11, 2011 at 17:52

3 Answers 3

7

Use .html instead of .text.

$(this).next('a').html('Liquid Handler #:<b>' + userInput + '</b>');
Sign up to request clarification or add additional context in comments.

Comments

3

jQuery's .html() method should help.

Comments

1

You could change your .text to .html but bear in mind this is prone to problems in the long run seeing as you'll have to escape anything that goes through it. A better way might be to do something like this:

$(this).next('a').text('Liquid Handler #:').append($("<b>").text(userInput));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.