javascript - How to change web page content without removing any style/css/graphics -
i'm trying change content in page through refresh button, using javascript or jquery. want change content in table, command use removes parts of table , leaves new content in white.
so far, i' ve tried change()
, replacewith()
, load()
, text()
of remove parts of table. document.write()
prints in new page.
is there command can use replace written table new content?
update:
code
<script> var result = []; var k = 0; var jsonobject = json.parse(eventsjson); $(document).ready(function(){ $("#priceinfob").on("click", function(){ //alert(jsonobject.events.event[0].name); (i=0;i<4;i++){ if (jsonobject.events.event[i].isfree == "true"){ result[k] = jsonobject.events.event[i].name; k++; } } $("#events").text(result[0] + result[1]); $('#mytable').remove(); }); });
<table id="mytable"> <tr class="head"> <th></th> <th>new york</th> <th>chicago</th> <th>san francisco</th> </tr> <tr> <th>blabla</th> <td>sat, 4 feb 2012<br />11am - 2pm</td> <td>sat, 3 mar 2012<br />11am - 2pm</td> <td>sat, 17 mar 2012<br />11am - 2pm</td> </tr> var eventsjson='{"events":{"event":[{"id":"1","name":"a poetic perspective","isfree":"true","locations":[{"location":"new york","eventdate":"2015-05-02","eventtime":"14:00"},{"location":"chicago","eventdate":"2015-05-01","eventtime":"14:00"},{"location":"san francisco","eventdate":"2015-06-01","eventtime":"15:00"}],"descr":"vivamus elementum, diam eget ullamcorper fermentum, ligula libero euismod massa, quis condimentum tellus lacus sit."},{"id":"2","name":"walt whitman @ war","isfree":"false","locations":[{"location":"new york","eventdate":"2015-07-02","eventtime":"14:00"},{"location":"chicago","eventdate":"2015-07-01","eventtime":"14:00"},{"location":"san francisco","eventdate":"2015-08-01","eventtime":"15:00"}],"descr":"donec convallis eu metus eget dictum. etiam non lobortis dui."},{"id":"3","name":"found poems & outsider poetry","isfree":"false","locations":[{"location":"new york","eventdate":"2015-06-02","eventtime":"11:00"},{"location":"chicago","eventdate":"2015-07-01","eventtime":"14:00"},{"location":"san francisco","eventdate":"2015-06-01","eventtime":"15:00"}],"descr":"ut fermentum, elit vel iaculis viverra, dui libero ultrices nibh, ut ornare."},{"id":"4","name":"natural death: exploration","isfree":"true","locations":[{"location":"new york","eventdate":"2015-05-02","eventtime":"14:00"},{"location":"chicago","eventdate":"2015-05-01","eventtime":"14:00"},{"location":"san francisco","eventdate":"2015-06-01","eventtime":"15:00"}],"descr":"lorem ipsum dolor sit amet, consectetur adipiscing elit. praesent aliquet urna ut tortor consequat."}]}}';
this update table supplied json...
http://jsfiddle.net/archersfiddle/eemxvu0z/
html
<table id="mytable"> <tr class="head"> <th></th> <th>new york</th> <th>chicago</th> <th>san francisco</th> </tr> <tr> <th>blabla</th> <td>sat, 4 feb 2012<br />11am - 2pm</td> <td>sat, 3 mar 2012<br />11am - 2pm</td> <td>sat, 17 mar 2012<br />11am - 2pm</td> </tr> </table>
javascript
var data = json.parse(eventsjson); function showevent(id) { (var in data.events.event) { if (data.events.event[i].id == id) { var thisevent = data.events.event[i]; var head = "<tr class=\"head\"><th></ht>"; var row = "<tr><th>" + thisevent.name + "</th>"; (var l in thisevent.locations) { var thislocation = thisevent.locations[l]; head += "<th>" + thislocation.location + "</th>"; row += "<td>" + thislocation.eventdate + "<br/>" + thislocation.eventtime + "</td>"; } head += "</tr>"; row += "</tr>"; $("#mytable").html(head + row); } } } showevent(4); // example
basically, rebuild html table supplied data , use $("#mytable").html(html);
update it. expect you'll using event, such select value change, trigger table update, use showevent(id);
function call update it.
Comments
Post a Comment