Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript template literals html

// Create our object
const person = {
    name: 'TopCoder2021',
    job: 'Software Developer,
    city: 'Los Angeles',
    bio: 'Tony is a really cool guy that loves to code!'
}

// And then create our markup:
const markup = `
 <div class="person">
    <h2>
        ${person.name}
    </h2>
    <p class="location">${person.city}</p>
    <p class="bio">${person.bio}</p>
 </div>
`;

document.body.innerHTML = markup
Comment

using template literals to create html

const createMarkup = function createMarkup(data) {
  // Just use the same syntax for node elements
  const markup = 
    `<ul id="listItem-${data.name}">
      <li>Name: ${data.name}</li>
      <li>Age: ${data.age}</li>
      <li>Gender: ${data.gender}</li>
      <li>Fav. Colour: ${data.colour}</li>
      <li>Lucky Number: ${data.number}</li>
    </ul>`;return markup;
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: Routes in react-router-dom@6 and take the path by useLocation() hook 
Javascript :: react hook form reset only one field 
Javascript :: js date in arabic 
Javascript :: kotlin jsonobject to class 
Javascript :: angular retry interceptor 
Javascript :: break statement in javascript 
Javascript :: sum of array javascript 
Javascript :: how to copy all the elements of an array except the last one in javascript 
Javascript :: get value of textarea jquery 
Javascript :: js validation library 
Javascript :: update array of objects with use state 
Javascript :: js library for unique id uniqid 
Javascript :: node 10 form data 
Javascript :: connect to localhost react native 
Javascript :: javascript array from string 
Javascript :: javascript simple hash 
Javascript :: axios react js 
Javascript :: cookies in react native 
Javascript :: cra proxy 
Javascript :: MONGOOSE update on by body 
Javascript :: add event listener to all a tags 
Javascript :: handling event in jsx 
Javascript :: mangoose connection 
Javascript :: javascript swap images on mouseover 
Javascript :: javascript ascii character a to z 
Javascript :: let javascript 
Javascript :: how to set button width in javascript 
Javascript :: tailwindcsss next js change font 
Javascript :: create multiple images in js 
Javascript :: if else jsx 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =