0

Trying to print JS var run_name as a part of HTML content. Here is my small snippet out of my entire JS code:

var run_name = uiscripts.context.run.id; //uiscripts.context.run.id is a string
var markUp = "<h3 class='title' style='text-align: center'>Job is _____</h3>\r\n"; 
$("#startJobDialog").html(markUp);

markUp var holds the HTML content that I want to show as a part of #startJobDialog. You can see the blank underlined content in markUp var. I want to fill run_name var into that blank. That is Job is _____. How do I do it?

So far I have tried 2 approaches:

var markUp = "<h3 class='title' style='text-align: center'>Job is <var>run_name</var></h3>\r\n"; 

and this:

var run_name = uiscripts.context.run.id;
    var markUp = "<h3 class='title' style='text-align: center'>Job is _____</h3>\r\n";

    markUp += run_name;

    $("#startJobDialog").html(markUp);

4 Answers 4

1

Try this. You simply need to concatenate the value of variable run_name with html.

var markUp = "<h3 class='title' style='text-align: center'>Job is <span style='font-weight:bold'>"+run_name+"</span></h3>\r\n"; 
Sign up to request clarification or add additional context in comments.

4 Comments

This solved my question, but flexibility in terms of color and font would be better for the var run_name. Is <var color="something"> doable? I want to do something right in this line and may not be CSS. Suggestions.
I didn't get you ?
I am not sure, that you should use <var> tag at all. To change the text colour you should use CSS.
Can I print var run_name in bold or italic way? I also want to highlight the the value of var, maybe by some color.
1

Try this:

var run_name = uiscripts.context.run.id; //uiscripts.context.run.id is a string
var markUp = "<h3 class='title' style='text-align: center'>Job is " + run_name + "</h3>\r\n"; 

$("#startJobDialog").html(markUp);

Also, In ES6 you can use interpolation within template literals. If put string in `` and wrap variable into ${run_name}

Comments

0

You can do it simply by defining #startJobDialog in a different way :-

<div id = "startJobDialog">
<h3 class='title' style='text-align: center'>
Job is <div id = "run_name"> </div>
</h3>
</div>

Jquery:-

$("#run_name").html(run_name);

Since your markup is not variable so you can put in in html itself. Or you can just concatenate run_name in your markup variable using + markup +

Comments

0

try the following

var markUp = $('<h3>',{
class:'title',
style:'text-align: center',
text:"Job is "+run_name });
$("#startJobDialog").html(markUp);

2 Comments

$('<h3>',{ quotes are missing and ; should not have to be there after variable.
Not sure $("#startJobDialog").append(markUp); does not work but this: $("#startJobDialog").html(markUp); does.

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.