2

How To Output Variable data And String With Single Quotes.I Want To Add String After The Value Of mo.Output Should Be Inside Single Quotes. Output Should Be:- '123target'

<button value="123" class="btn">Button 1</button>
$('.btn').click(function(){
   var mo = $(this).val();
   var re = '''+mo+'target'';
   document.write(re);
});

4 Answers 4

4

Use double quote to wrap or escape it using \.

var re = '\'' + mo + 'target\'';
// or
var re = "'" + mo + "target'";
Sign up to request clarification or add additional context in comments.

Comments

1

Try this,

$('.btn').click(function(){
   var mo = $(this).val();
   var re = "'"+mo + "target'";
   document.write(re);
});

Check jsfiddle link.

You haven't kept quotes properly.

Comments

1

$('.btn').click(function() {
  var mo = $(this).val();
  var re = "'" + mo + "target'";
  document.write(re);
});
<button value="123" class="btn">Button 1</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

Comments

1

additionally you can also use ES6 template strings (backtics)

var mo = "quotes"
out.innerHTML=`some string in 'single ${mo}' and some in "double ${mo}" and also some "mix'd ${mo} content"`
<div id="out"></div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.