最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to display a variable value along with the text in .html() - Stack Overflow

programmeradmin1浏览0评论

Hi I have a requirement of printing the value is the popup, I have used the below code

"code"

$('#warning').html('<p style="font-size: 12px;padding-top: 13px;">The updated list value is <p>' + var11);

but i wanted the value 500 to be displayed next to the text in the same line

can some one help me out with this

Thanks

Hi I have a requirement of printing the value is the popup, I have used the below code

"code"

$('#warning').html('<p style="font-size: 12px;padding-top: 13px;">The updated list value is <p>' + var11);

but i wanted the value 500 to be displayed next to the text in the same line

can some one help me out with this

Thanks

Share Improve this question edited Jun 27, 2020 at 16:47 ABGR 5,2454 gold badges32 silver badges55 bronze badges asked Jun 18, 2020 at 6:13 Dodo dodoDodo dodo 592 silver badges9 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 4

Just need to concenenate with + inside the <p> tag.

var var11 = 500
$('#warning').html('<p style="font-size: 12px;padding-top: 13px;">The updated list value is ' + var11+'<p>' );
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="warning"></div>

Hope this helps

Just add the variable to the text of <p> tag also you can use Template strings:

$('#warning').html(`<p style="font-size: 12px;padding-top: 13px;">The updated list value is ${var11} <p>` );

Get your variable inside the p tag :

$('#warning').html('<p style="font-size: 12px;padding-top: 13px;">The updated list value is' + var11 + ' <p>');
发布评论

评论列表(0)

  1. 暂无评论