-3

I would like to change the following line:
$("<ul><li><a href="+url">"+displayName + "</a>"+"<br>"+description+"</br></li></ul>".appendTo(".results")

into the next string:
$("<ul><li><a href={0}> {1}" + "</a>"+"<br>"+description+"</br></li></ul>",{0:url, 1:displayName}.appendTo(".results").

however, instead of displayName i get 1. please help to fix this As you can see i've tried to write it like in c#

4
  • looks a little like string.format from c#, look here stackoverflow.com/questions/2534803/… Commented Nov 16, 2017 at 16:33
  • 1
    if you have ES6 then you can use string interpolation Commented Nov 16, 2017 at 16:34
  • Please format your question better it's hardly legible. Commented Nov 16, 2017 at 16:40
  • i tried format by myself but, even this code at question is messed up, the tags are made with html symbols Commented Nov 16, 2017 at 17:02

1 Answer 1

1

Using ES6 string interpolation, it would look like this:

$(`
  <ul>
    <li>
      <a href=${url}> ${displayName}</a>
      <br>${description}</br>
    </li>
  </ul>
`).appendTo(".results");

Notice the back-ticks instead of double-quotes.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you but itsstill show the word displayName and not the Name of the item

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.