Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<head>
<title>Weather API</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="currentweather.js"></script>
</head>
<body background="http://res.cloudinary.com/dwjej2tbp/image/upload/v1523434737/pexels2_w3plbq.jpg" style="background-repeat:no-repeat;">
<div class="text-center container-fluid">
<h1 class="well well-lg" style="padding:20px;background-color:#46acdd;color:white;font-weight:bold;">Current Weather App</h1>
<h3 style="font-weight:bold;color:white;">Enter City Name<h3>
<span id="error"></span>
<input type="text" placeholder="Type city name" name="txt" id="city" style="padding:10px;"/>
<input type="button" id="submitWeather" class="btn btn-primary btn-lg" value="Search"/>
</div>
<div id="show" class="container-fluid" style="margin:auto;width:80%;"></div>
<!--<div class="well well-lg container-fluid text-center" style="padding:10px;margin-top:380px;background-color:#46acdd;color:white;font-weight:bold;">Copyright 2018 @BoopalanSundaramoorthy. 
</div>-->
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                $(document).ready(function(){
	
	$('#submitWeather').click(function(){
		
		var city = $('#city').val();
		
		if(city != '')
		{
			$.ajax({
				url:'https://api.openweathermap.org/data/2.5/weather?q=' + city + "&units=metric" +
				"&APPID=eece51e37a2d70127303cfadfaa28994",
				type: "GET",
				dataType: "jsonp",
				success: function(data){
					//console.log(data);
					var widget = show(data);
					
					$("#show").html(widget);
					
					$('#city').val('');
				}
				
				
			});
		}
		else
		{
			$('#error').html("<div class='alert alert-danger text-center'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>Field Cannot be Empty</div>");
		}
		
	});
});
function show(data)
{
	return "<h2 style='font-size:30px;color:yellow;font-weight:bold;' class='text-center'>Current Weather for " +data.name + ", " + data.id + ", " + data.sys.country + "</h2>" +		
		"<h4 style='color:white;'><strong>Longitude:</strong>: " + data.coord.lon + "</h4>" +
		"<h4 style='color:white;'><strong>Latitude:</strong>: " + data.coord.lat + "</h4>" +	
		"<h4 style='color:white;'><strong>Weather</strong>: " + data.weather[0].main + "</h4>" +
		"<h4 style='color:white;'><strong>Description</strong>: <img src='http://openweathermap.org/img/w/"+data.weather[0].icon+".png'>" + data.weather[0].description +"</h4>" +
		"<h4 style='color:white;'><strong>Temperature</strong>: " + data.main.temp +"&deg;C</h4>" +
		"<h4 style='color:white;'><strong>Pressure</strong>: " + data.main.pressure +" hPa</h4>" +
		"<h4 style='color:white;'><strong>Humidity</strong>: " + data.main.humidity +"%</h4>" +
		"<h4 style='color:white;'><strong>Minimum Temperature</strong>: " + data.main.temp_min +"&deg;C</h4>" +
		"<h4 style='color:white;'><strong>Maximum Temperature</strong>: " + data.main.temp_max +"&deg;C</h4>" +
		"<h4 style='color:white;'><strong>Wind Speed</strong>: " + data.wind.speed +"m/s</h4>" +
		"<h4 style='color:white;'><strong>Wind Direction</strong>: " + data.wind.deg +"&deg;C</h4>";
}
              
            
!
999px

Console