
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
안녕하세요.
JQuery로 api에서 온도가져오는 기능을 배웠는데요.
$(' ').text( ) 와 $(' ').append( )의 차이를 알고싶어요. 저는 temp_html 변수만들고 append()로 썼거든요.
가져올 단어가 하나랑 굳이 temp_html안만들고, text()를 쓴건가요?
let temperature = data['temp']
let temp_html = `${temperature}`
$('#temp').appendt(temp_html)
위에 있는 코드는 제가 제일 먼저 생각했던 정답.
밑에 있는 코드가 강의에서 온 정답.
function set_temp() {
$('#temp').empty()
fetch("http://spartacodingclub.shop/sparta_api/weather/seoul")
.then((res) => res.json())
.then((data) => {
// console.log(data['temp'])
let temperature = data['temp']
$('#temp').text(temperature)
});
}
