Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:48:40+00:00 2026-06-03T05:48:40+00:00

I am creating a Javascript class The class is this (function(window){ function Person(id,name,position,imageUrl){ this.id

  • 0

I am creating a Javascript class

The class is this

(function(window){

    function Person(id,name,position,imageUrl){

    this.id = id;
    this.name = name;
    this.position = position;
    this.imageUrl = imageUrl;

    }

    Person.prototype.getPersonDiv = function(){

      var persondiv; 

    }

}(window));

I am using this class to create a div on the fly. The basic structure of the div will be like this

<div id = "employee1" class = 'person-profile'>

 <div class = 'avatar'>
   <img src = ""/>
 </div>

 <div class = 'employee-details'>
   <p>this.id <br/> this.name <br/> this.position<p>   
 </div>

</div>

The div id employee1 is to be made by concatenating string ’employee’ and id (the property of the class). Similarly img url should come from imageUrl(the property of the class).Similarly all employee details.

What I am planning is to write it as inner HTML or appending. I cant seem to get the making to string correct.

The string will be written to persondiv variable in getPersonDiv function and returned when I invoke the function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:48:42+00:00Added an answer on June 3, 2026 at 5:48 am

    you could try something like this, using some kind of javascript microtemplating :

    (function(window){
    
        function Person(id,name,position,imageUrl){
    
        this.id = id;
        this.name = name;
        this.position = position;
        this.imageUrl = imageUrl;
    
        }
    
        Person.prototype.getPersonDiv = function(){
          var _this = this;
    
          /* create basic person template */
          var personTPL = "<div class = 'employee-details'>"
              + "<p>{id}<br/>{name}<br/>{position}<p></div>";
    
          /* change any placeholder with instance properties */
          return personTPL.replace(/\{([^}]+)\}/g, function(tpl, key) {
                 return  _this[key] || "undefined"
              });  
        };
    
    
         var me = new Person("10", "Fabrizio", "javascriptmonkey", "http://...");
    
         /* return HTML */
         console.log(me.getPersonDiv());
    
         /** e.g.
          *
          * <div class = 'employee-details'><p>10<br/>
          * Fabrizio<br/>javascriptmonkey<p></div>  
          */
    }(window));
    

    Example fiddle : http://jsfiddle.net/6qZg5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a JavaScript class (using Prototype) that will set the page state to
Possible Duplicate: JavaScript: Class.method vs. Class.prototype.method What's the difference between creating a prototype like
I am creating a JavaScript class. Some of the methods contain AJAX calls using
I'm creating some on runtime. For that I'm using this function: function creatediv(id, html,
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
I'm trying to create a JavaScript program using the innerHTML function wherein the user
I am creating a list of links using a knockout binding: The Javascript and
I am creating a JavaScript class called ImageRotatorManager to manage a dynamically-loaded slideshow. When
I have some experimental input checking Javascript: $(function(){ var check_stuff = function(elem){ //...code to
I am creating a Javascript object that contains a function that executes a jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.