Weebs
Weebs

Reputation: 175

How do I change the value of an appended string?

I am grabbing the date of a blog post from a page on a site and displaying it on another page on the same site.

The date reads 2/22/18 on the initial page and the jQuery code below successfully strips it to just "2" and appends it to the div with the "box-month-1" class on the second page. However, I want to change the value of that "2" to "FEB", but I can't get it to work. I'd appreciate any help anyone can offer! Thanks in advance.

HTML

<div class="box-month-1"></div>  

jQuery

$.get('/blog.html', function(data){   

  var s = $(data).find('.blog-date .date-text').text().split('/').slice(0,1).join('/');
  $('.box-month-1').append(s);

  var boxOne = $('.box-month-1').text();

  var jan = "JAN";
  var feb = "FEB";
  var mar = "MAR";

  if (boxOne.equals('2')) {
    $('.box-month').replaceWith(feb);
  }

});

Upvotes: 1

Views: 50

Answers (1)

Supun Praneeth
Supun Praneeth

Reputation: 3160

Try this:

      $.get('/blog.html', function(data){   

      var s = $(data).find('.blog-date .date-text').text().split('/').slice(0,1).join('/');
      $('.box-month-1').append(s);

      var boxOne = $('.box-month-1').text();

      var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul","Aug","Sep", "Oct", "Nov", "Dec"]; 

        $('.box-month-1').html(months[parseInt(boxOne)+1]); 

    });

Upvotes: 1

Related Questions