javascript - Using jQuery to rearrange page elements -



javascript - Using jQuery to rearrange page elements -

i'm relatively new jquery , javascript, , think understand causing issue, i'm not sure how prepare it.

i'm using simpleweather.js , moment.js, , moment.js timezone current time , weather 4 cities. have info want on page, want move each city's time sec paragraph in each city's div. ideas on how working current code or there more efficient way of producing result?

http://jsfiddle.net/ljd144/p6tpvz1r/

here's js:

$(document).ready(function () { $('.weather').each(function () { var city = $(this).attr("city"); var woeid = $(this).attr("woeid"); var degrees = $(this).attr("degrees"); var continent = $(this).attr("continent"); $.simpleweather({ zipcode: '', woeid: woeid, location: '', unit: degrees, success: function (weather) { if (continent == 'america'){ html = '<p>' + weather.city + ', ' + weather.region + '</p>'; } else { html = '<p>' + weather.city + ', ' + weather.country + '</p>'; } //html += '<p class="time" id="'+city+'></p>'; //html += '<p>' + weather.updated + '</p>'; html += '<p><i class="icon-' + weather.code + '"></i> ' + weather.temp + '&deg;' + weather.units.temp + '<p>'; html += '<p>' + weather.currently + '<p>'; $('#weather_' + city).html(html); }, error: function (error) { $('#weather_' + city).html('<p>' + error + '</p>'); } }); }); $(function () { setinterval(function () { $('.time').each(function () { var city = $(this).attr("city"); var continent = $(this).attr("continent"); //$(this).text(city); var utc = moment.utc().format('yyyy-mm-dd hh:mm:ss'); var localtime = moment.utc(utc).todate(); citytime = moment(localtime).tz(continent + "/" + city).format('ddd mmm d yyyy, h:mm:ss z'); $(this).text(city+ ': '+citytime); }); }, 1000); }); $('.time').each(function () { var city = $(this).attr("city"); //$('#weather_' + city).after(this); }); });

you can utilize appendto() method append time respective <div> having same city attribute using attribute equals selector like:

$(this).text(city + ': ' + citytime).appendto("div[city='"+city+"']"); updated fiddle

javascript jquery momentjs

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -