jQuery addClass example

Change class name on click in jQuery

by Dhanck

HTML

<!-- <input type="button" id="basicFetchButton" value="Try it">
<div class="format">format</div> -->
<div class="response"></div>

<div class="title"></div>
  <div class="desc"></div>

JavaScript

/* function pull_news() {
  // Loading the jQuery code
  fetch("https://gnews.io/api/v2/?q=agrimoney&token=5fc59161aafbf359a02b6dbc4223891c")
    .then(function(response) {
     response.text().then(function(responseText, articles) {
     
            $('.response').html(responseText);
            $('title').append(articles.title)

          });
    });
    
}
 */



(function($) {
var url = 'https://gnews.io/api/v2/?q=agrimoney&token=5fc59161aafbf359a02b6dbc4223891c';

$.ajax({
   type: 'GET',
    url: url,
    async: false,
    jsonpCallback: 'callback',
    contentType: "application/json",
    dataType: 'json',
    success: function(json) {
       console.log(JSON.stringify(json.articles));
       $.each(json.articles, function(idx, articles){
         $(".response").append('<div>' + articles.title + articles.desc + "</div>");
       });
    },
    error: function(e) {
       console.log(e.message);
    }
});

})(jQuery);





//pull_news();


/* document.getElementById("basicFetchButton").addEventListener("click", 

var txt = '{"name":"John", "age":30, "city":"New York"}'
var obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;


function() {
  // Loading the jQuery code
  fetch("https://gnews.io/api/v2/?q=agrimoney&token=5fc59161aafbf359a02b6dbc4223891c")
    .then(function(response) {
      response.text().then(function(responseText) {
        $('.response').html(responseText);
        
      });
    });
});
 */




/* $('.format').on('click', function(){
var obj = jQuery.parseJSON('{"timestamp":1554298436,"count_results":10,"articles":[{"title":"EU rapesed imports to hit record high in 2019-20","desc":"but this looks unlikely to mean a surge in purchases from Canada, which is seeking to find a replacement buyer to China for its...