Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery find and replace text based on key value pair object
    primarykey
    data
    text
    <p>i've rummaged around and found some useful posts for doing find / search / replace in jquery using a key value pair array / object, </p> <p>but i can't get it to work, </p> <p>here's the site's test URL:</p> <p><a href="http://www.larryadowns.com.php5-1.dfw1-2.websitetestlink.com/" rel="nofollow">http://www.larryadowns.com.php5-1.dfw1-2.websitetestlink.com/</a></p> <p>as you can see, it's a blog feed with post info. i'm trying to target the date months, and do a search and replace for each to put in the spanish months.</p> <p>here's the javascript, it's all wrapped in a jQuery(document).ready()...</p> <pre><code> var monthMap = { "January" : "Enero", "February" : "Febrero", "March" : "Marzo", "April" : "Abril", "May" : "Mayo", "June" : "Junio", "July" : "Julio", "August" : "Agosto", "September" : "Septiembre", "October" : "Octubre", "November" : "Noviembre", "December" : "Diciembre" }; // sift thru the post-info, replacing only the month with the spanish one. $(".post-info .date").text(function(index, originalText) { var moddedText = ''; for ( var month in monthMap ) { if (!monthMap.hasOwnProperty(month)) { continue; } moddedText = originalText.replace(month, monthMap[month]); // moddedText = originalText.replace( new RegExp(month, "g") , monthMap[month] ); console.log("month : " + month); console.log("monthMap[month] : " + monthMap[month]); } console.log('-------------------'); console.log('index : ' + index); console.log("monthMap : " + monthMap); console.log("originalText : " + originalText); console.log("moddedText : " + moddedText); return moddedText; }); </code></pre> <p>but alas, neither the .replace or the .replace with the RegEx are really replacing anything. where did i go wrong? ty again stack.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload