study/Web

HTML 기본_spartacoding 3 (jQuery)

hi_i 2022. 1. 25. 01:46

jQuery




HTML의 요소들을 조작하는 편리한 javascript를 미리 작성해둔 라이브러리!

import 하여 html제작시 불러와 사용할 수 있다.

jQuery임포트 링크 내에
 https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
구문을 추가하여 jQuery를 임포트 시킬 수 있다.

 

//일반 코드

document.getElementById("element").style.display = "none";

위의 일반 코드를 jQuery를 활용하여 아래와 같은 코드로 짧고 간결하게 작성할 수 있다.


//jQuery를 이용한 코드

$('#element').hide();

 


Ajax




jQuery를 임포트한 페이지에서만 동작가능하다.

Ajax 기본골격

$.ajax({
  type: "GET",
  url: "여기에URL을입력",
  data: {},
  success: function(response){
    console.log(response)
  }
})


url내의 값을 response에 전달한다.