JQuery fails to render to page, but no errors -


i'm using jquery modify , replace following html

<div class="weather-feed">     <img src="http://l.yimg.com/a/i/us/we/52/32.gif"/><br />     <b>current conditions:</b><br />     sunny, 17 c<br />     <br /><b>forecast:</b><br />     wed - sunny. high: 27 low: 14<br />     thu - sunny. high: 25 low: 14<br />     fri - partly cloudy. high: 26 low: 15<br />     sat - partly cloudy. high: 27 low: 17<br />     sun - partly cloudy. high: 28 low: 17<br />     <br />     <a href="http://us.rd.yahoo.com/dailynews/rss/weather/pretoria__sf/*http://weather.yahoo.com/forecast/sfxx0044_c.html">full forecast @ yahoo! weather</a><br/><br/>     (provided <a href="http://www.weather.com" >the weather channel</a>)<br/> </div> 

this code retrieved onto page (into div specifically) through php session. div there selection (and styling later on).

because lot of html doesn't have identifiable containers, i'm using regex isolate text (such weather conditions , forecast):

$(document).ready(function() {     var src = $(".weather-feed");      // remove line feeds     src.find("br").remove();      // weather conditions         var result = "<div class=\"weather-conditions\">";     result += src.html().match(/<\/b>([^<]*)<b>/)[1].trim();     result += "</div>";      // weather icon     result += "<div class=\"weather-icon\"><img src=\"" + src.find("img").attr("src") + "\" /><span><?php echo($city); ?></span></div>";      // more button     result += "<div class=\"weather-more-button\">+</div>";      // weather forecast     result += "<div class=\"weather-extra\">";     result += "<div class=\"weather-forecast\">";     result += src.html().match(/<\/b>([^<]*)<a/)[1].trim().replace("\n", "<br />");     result += "</div>";       // addition forecast link     result += "<div class=\"weather-detail\">";     result += $("<div/>").html(src.find('a').first()).html();     result += "</div></div>";      console.log(result);      // write new code page                src.empty();     src.append(result); }); 

unfortunately, while jquery produces no errors , logs result correctly (see below) console, new code isn't rendered page. i'm seeing there still original code returned php.

<div class="weather-conditions">     sunny, 17 c </div> <div class="weather-icon">     <img src="http://l.yimg.com/a/i/us/we/52/32.gif" />     <span>pretoria</span> </div> <div class="weather-more-button">+</div> <div class="weather-extra">     <div class="weather-forecast">         wed - sunny. high: 27 low: 14<br />         thu - sunny. high: 25 low: 14         fri - partly cloudy. high: 26 low: 15         sat - partly cloudy. high: 27 low: 17         sun - partly cloudy. high: 28 low: 17     </div>     <div class="weather-detail">         <a href="http://us.rd.yahoo.com/dailynews/rss/weather/pretoria__sf/*http://weather.yahoo.com/forecast/sfxx0044_c.html">full forecast @ yahoo! weather</a>     </div> </div> 

additionally (and think there's chance it's related), replacement of \n <br /> under weather forecast section isn't working more 1st match , i'm @ loss why is.

if can assist here in way, i'd appreciate it.

here's fiddle can see what's going on: http://jsfiddle.net/4uyaj/


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -