public
Description: PURE Unobtrusive Rendering Engine for HTML
Home | Edit | New

Basic - hello who?

The first example is about replacing the HTML ‘Hello World’ below by ‘Hello Mary’.
The word ‘Mary’ is coming from a JSON.

 

The HTML:

<div id="hello">
  Hello <span class="who">World</span>
</div>

 

The JSON data:

var json = { "who": "Mary" }

 

The Javascript to do this action (here with jQuery):

$('#hello').autoRender( json );

 

Note:

The notations below are also possible with different results:

  1. Replacing ‘target’ by ‘hello’ transformed by the json
    $('#target').autoRender(json, $('#hello'));
  2. Replacing the content of a target (its innerHTML)
    $('#target').html( $p.autoRender( $('#hello')[0], json));
  3. The same as above, but with a classical Javascript syntax:
    var target = document.getElementById('target1'); 
    var html = document.getElementById('hello');
    var json = { "who": "Mary" };
    target.innerHTML = $p.autoRender( html, json );
Last edited by pure, Sat Sep 20 07:48:18 -0700 2008
Home | Edit | New
Versions: