I have a block of text that I'm bringing over from an XML file using JQuery. There are breaks in the text that I'd like to put "<br>" tags into, but XML doesn't like those tags, so I'm substituting them for "\n" and doing a str.replace(/\n/g, "<br>"); but instead of replacing the "\n" it's just adding the "<br>". Is there a better way to handle this?
Any suggestions would be greatly appreciated!
Here's my code, maybe I'm just doing something wrong:
Code:var movies = $(xml).find("movie"); movie = movies[id]; image_name = $("thumbnail", movie).text() == "" ? "movie_art/missing.jpg" : $("thumbnail", movie).text(); image = $("<img>").attr("src", image_name).attr("height", 225).attr("width", 150); title = $("<h1>").html($("title", movie).text()); year = $("<h2>").html($("year", movie).text()); cast = $("<div id='cast'>").html("<h3>Cast</h3>"); cast_list = $("<ul>"); $("cast", movie).each(function(){ $(cast_list).append("<li>"+$(this).attr("character").capitalize()+": "+$(this).text()+"</li>"); }); cast.append(cast_list); plot = $("<div id='plot'>").html("<h3>Plot</h3>"+$("plot", movie).text().replace(/\n/g, "<br><br>")); $("#content").append(image).append(title).append(year).append(cast).append(plot);


Reply With Quote
Bookmarks