0

I want to create html element using JavaScript

<p id="user1" class="user-list-follow">
   <img src="../images/pictures/1s.jpg" alt="img">
   <strong>User One<br><em>Some sample text here.</em></strong>
   <a href="#" class="follow">Follow</a>
</p>
<div class="decoration"></div>

Please help me.

5
  • What kind of html element? Do you mean the whole code that you have poster here? Commented Mar 29, 2018 at 11:16
  • I'm pretty sure you can find this information anywhere with little effort. Commented Mar 29, 2018 at 11:16
  • How is it easier to open a new question here than to spend 30 seconds googling? Commented Mar 29, 2018 at 11:17
  • Where is your research efforts? Commented Mar 29, 2018 at 11:18
  • thanks @Tanmay i do research ..... now this code is working for me for (var i = 0; i < teams.length; i++) { listItems += "<p class='user-list-follow'><img src='../images/pictures/1s.jpg' alt='img'><strong>"+ teams[i]['Associate_Name']+"<br><em>"+ teams[i]['member_id']+"</em></strong><a href='#' class='follow'>More</a></p><div class='decoration'></div>"; } $('#ulist').html(listItems); Commented Apr 4, 2018 at 11:55

1 Answer 1

3

In an HTML document, the document.createElement() method creates the HTML element specified by tagName, or an HTMLUnknownElement if tagName isn't recognized.

var element = document.createElement(tagName[, options]);

tagName

A string that specifies the type of element to be created. The nodeName of the created element is initialized with the value of tagName. Don't use qualified names (like "html:a") with this method. When called on an HTML document, createElement() converts tagName to lower case before creating the element. In Firefox, Opera, and Chrome, createElement(null) works like createElement("null").

options(Optional)

An optional ElementCreationOptions object containing a single property named is, whose value is the tag name for a custom element previously defined using customElements.define(). See Web component example for more details.

DEMO

var btn = document.createElement("BUTTON"); // Create a <button> element
var t = document.createTextNode("CLICK ME"); // Create a text node
btn.appendChild(t); // Append the text to <button>

btn.onclick=function(e){
alert('You have clicked me..');
}
document.body.appendChild(btn); // Append <button> to <body>

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

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.