• JQuery - Quick Self Study & JQuery Note For IT Student
JQuery - Quick Self Study & JQuery Note For IT Student

1) Remember to save jquery.js library to your LIBCode folder in order to copy it to the /js folder later or you can remmember this CDN 

2) Put the jquery library inside the  tags <head><script src="/js/jquery.js"></script></head>

3) Select element by ID using jquery --> $("#elementID")

4) Select element by Class using jquery --> $(".elementClass")

5) Always remember $ sign and . for class and # for ID

6) Get value --> var name = $("#elementID").val();
    Set value --> $("#elementID").val("New value");

// Select checkbox doing the same .val(); to get the value of the checkbox

7) Put jquery code inside this $(function(){ // code here }); So this will run the jquery right after the html page is rendered and loaded ( khi trang html load hết, các phẩn tử đều hiển thì thì sau đó jquery mới chay để tránh bị lỗi ko tìm thấy element)

8) $.post("/action-url",{param1:param1}, function(data){}); // Using post to submit the form to the action-url with param1. data is the html render of the /action-url

9) $("#elementID").html() --> Get html code inside element elementID;
    $("#elementID").html("New Content") --> Set html code inside element elementID;

10) .hide() .show() .toggle() 

11) $("#elementID").css({"":""}) // Set style for elementID

12) addClass("classname") removeClass("classname");

13) $("#elementID").find("#anotherElementID") // find elements inside element

14) $(".elementClass").eq(0); // select element index = 0 of .elementClass group

15) $("#elementID").attr("data-atribute"); // get attribute of elementID

16) $("#elementID").attr("data-atribute","data-value"); // set value for attribute of elementID

17) [...]