create this HTML markup with Javascript ( a complex DL entry of Dt and DD) -


dear friends of stackoverflow, need make following html markup entry definition list "dl" thru javascript can make entry dynamically. need edit css values. put css entry after html. in dd entry there class, anchor class, href, text, anchor class, , href. don't know proper syntax enter these thru javascript. many help. markandeya

 <dt class="book2"><span>book2</span></dt>   <dd class="book2"><a class="amazonlink" href="http://www.amazon.co.uk/principles-beautiful-web-design/dp/0975841963%3fsubscriptionid%3dakiajcfyspa5v4zscm6q%26tag%3dstevwork-21%26linkcode%3dxm2%26camp%3d2025%26creative%3d165953%26creativeasin%3d0975841963"><img src="http://ecx.images-amazon.com/images/i/41fxc9u%2b%2bvl._sl160_.jpg" alt=""></a><br> <strong>beautiful web design</strong> jason beaird.<br> book teaches wide range of topics on how make great web sites, covering layout styles, ratios , colour theory.<br> <a class="publisherlink" href="#">beautiful web design on sitepoint</a>   </dd> 

css hard code class "book2" is: ( need syntax edit entries thru javascript)

dl.bookshelf dt.book2 {     background: url(img/beautdesign-spine.png) 0 0 no-repeat,     url(img/beautdesign-front.png) 40px 0 no-repeat;     left:52px;     width:280px;     z-index:2; } 

not same style output. publisher field can left off, , image not required store link. can set class json object store link. desc array, converted series of paragraphs. may not want, should @ least provide running start.

first, javascript:

var books = [     {         title: 'beautiful web design',         author: 'jason beaird',         link: {             cls: 'amazonlink',             href: 'http://www.amazon.co.uk/principles...',             img: 'http://ecx.images-amazon.com/images/...',             text: 'view on amazon'         },         publisher: {             href: '#',             name: 'sitepoint'         },         desc: [             'this book teaches you...'         ]     } ];  var bookshelf = document.getelementbyid('bookshelf');  for(var i=0,l=books.length;i<l;i++) {     var book = books[i];      var dt = document.createelement('dt');      var title = document.createelement('strong');     title.appendchild(document.createtextnode(book.title));      dt.appendchild(title);     dt.appendchild(document.createtextnode(' ' + book.author));      var dd = document.createelement('dd');      if(book.link.href !== null) {         var link = document.createelement('a');         link.setattribute('class',book.link.cls);         link.setattribute('href',book.link.href);          if(book.link.img !== undefined && book.link.img !== null) {             var img = document.createelement('img');             img.setattribute('src',book.link.url);             img.setattribute('alt',book.link.text);              link.appendchild(img);         }         else {             link.appendchild(document.createtextnode(book.link.text));         }          dd.appendchild(link);     }      if(book.desc !== undefined && book.desc instanceof array) {         for(var j=0,k=book.desc.length;j<k;j++) {             var p = document.createelement('p');             p.appendchild(document.createtextnode(book.desc[j]));             dd.appendchild(p);         }     }      if(book.publisher !== undefined) {         var pub = document.createelement('a');         pub.setattribute('class','publisherlink');         pub.setattribute('href',book.publisher.href);          pub.appendchild(document.createtextnode(book.title + ' on ' + book.publisher.name));          dd.appendchild(pub);     }      bookshelf.appendchild(dt);     bookshelf.appendchild(dd); } 

next, html output:

<dl id="bookshelf">     <dt>         <strong>beautiful web design</strong> jason beaird     </dt>     <dd>         <a class="amazonlink" href="..."><img src="..." alt="view on amazon"/></a>         <p>             book teaches you...         </p>         <a class="publisherlink" href="#">beautiful web design on sitepoint</a>     </dd> </dl> 

you can add classes , elements here or there make resultant html more descriptive , more responsive css.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -