0

I am working on a API, so i got it running but would like to apply some style to it.

I am trying to change the style for var title, country, status and summary without success. Could you hint on how to do it? I have tried a few things but none of them are working.

Thank you!

// creating an empty object to hold functionality of our app
var app = {};


// create an init method that will hold all the code that must run upon initialization of app
app.init = function(){
    $('#subject').on('keyup', function(){
  var subject = $(this).val().toLowerCase();
  //empty before we ask for result that were there so new results will show up
  $('#showresults').empty();
  app.getShow(subject);
});
};

// getShow method will make the Ajax request to the API
app.getShow = function(query){
    $.ajax({
        url: 'http://api.tvmaze.com/search/shows?q=:query',
        method: 'GET',
        dataType: 'json',
        data: {
            ps: 20,
            q: query,
            format: 'json'
        },
        success: function(results){
            console.log(results);
            app.displayShow(results);
        },
        error: function(error){
            console.log(error);
        }
    });
};



// displayShow will inject our art pieces into the DOM
app.displayShow = function(ShowArray){
    //forEach is the equivalent of for loop in jQuery. it is used to loop over our array of show
    ShowArray.forEach(function(showObject){
      //create a variable that will hold the html and the h that doesn't exist yet. we use artPiece.title because it's the place holder for the object
        var title = showObject.show.name  ;
        var country = showObject.show.network.country.name
        var status= showObject.show.status ;
        var summary =  showObject.show.summary ;
        //Adding all of our elements into this div

        var showHtml = $('<div>').addClass('series').append(title + '<br>' + country + '<br>' + status + summary);
        $('#showresults').append(showHtml);
    });
};


$(function(){ // shortform of document.ready, which waits for all of the HTML document to be loaded before running JS
    app.init();
});
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:700;}dfn{font-style:italic;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace, serif;font-size:1em;}pre{white-space:pre-wrap;word-wrap:break-word;}q{quotes:\201C \201D \2018 \2019;}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-.5em;}sub{bottom:-.25em;}img{border:0;}svg:not(:root){overflow:hidden;}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,html input[type=button],/* 1 */
input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer;}button[disabled],input[disabled]{cursor:default;}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0;}input[type=search]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;}body,figure{margin:0;}legend,button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}

.clearfix:after {visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }

* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }

body {
  font-family: "Roboto", "Arial", sans-serif;
  font-size: 20px;
}

main {
  background: #0B1C56;
  color: #fff;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 50px;
  overflow: hidden; /*clearfix*/
}

h1 {
  margin-top: 0;
}
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>TV SHOW APP</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <header>
    <div class="container">
      <h1 id="page-title">TV SHOW APP</h1>


<!---ADDED---->

      <form>
        <label for="subject">Choose your show</label>
        <input name="subject" id="subject">
        </input>
        
      </form>

<!---END OF ADDED---->
</div>
</header>

  <main>
    <div class="container" id="showresults"></div>
  </main>

  <script src="http://code.jquery.com/jquery-3.1.1.min.js"
          integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
          crossorigin="anonymous">
  </script>
  <script src="app.js"></script>
</body>
</html>

1
  • can you better explain what you're trying to do? Commented Apr 20, 2017 at 18:40

2 Answers 2

1

You can try something like this

var showHtml = $('<div>').addClass('series')
.append('<span class="titleClass">' +title  +'</span>' 
+ '<br> <span class="countryeClass">' + country +'</span>' 
+ '<br> <span class="statusClass">' + status + summary+'</span>' );
Sign up to request clarification or add additional context in comments.

Comments

0

You want to wrap the output for those variables in HTML elements, give the elements a class or some sort of identifier, then style them using CSS.

Here I'm wrapping the output text in spans, but you can use whatever is appropriate here.

var showHtml = $('<div>').addClass('series').append('<span class="title">' + title + '</span>' + '<br>' + '<span class="country">' + country + '</span>' + '<br>' + '<span class="status">' + status  + '</span>' + '<span class="summary">' + summary  + '</span>');

And here's some example CSS to style them

.title {
  color: red;
}
.country {
  color: white;
}
.status {
  color: blue;
}
.summary {
  color: lemonchiffon;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.