Solved

How do I use jQuery to change the order and contents of an element?

Posted on 2015-01-14
3
376 Views
Last Modified: 2015-01-15
Hi all,

On my page: http://www.clarktogei.jp/category/noko%E3%81%AE%E3%83%96%E3%83%AD%E3%82%B0/
I have a repeating element div.blogpost_date-block
Within it I have a date in this format: 01 1月 2015   (day month followed by "月" year)
I would like each of these blocks to be reformatted in this way: 2015年1月1日  (year followed by "年" then month followed by "月" day followed by "日")

I don't want to change the php in the template so I would like to do this runtime using jQuery for each of the elements.

Please assist.

thanks in advance
0
Comment
Question by:badwolfff
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Jeffrey Dake
Comment Utility
You could use the jquery ui library and use the date picker date format function.

http://sharepointroot.com/2012/10/31/format-datetime-in-javascript-using-jquery/
0
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
Comment Utility
You could try this:

$(".blogpost_date-block").each( function() {
   var str = $(this).text().replace(/(\d+)\s(\d+)月\s(\d+)/, "$3年$2月$1日");
   $(this).text(str);
});
0
 
LVL 24

Expert Comment

by:mankowitz
Comment Utility
I might have got that backwards. I am not familiar with chinese dates. If that doesn't work, then replace the string with "$3年$1月$2日"
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now