Before started
<script>
$(document).ready(function() {
// code here will run after browser load the document.
});
</script>
Purpose | Code |
---|---|
Select element by tag name | $("element") |
Select element by class | $(".class") |
Select element by id | $("#id") |
Select parent | $("element").parent(); |
Select children | $("element").children(); |
Select even/odd elements | $("element:odd") // zero-indexed |
Remove element | $("element").remove(); |
Move element | $("element").appendTo("targetContainer"); |
Clone element | $("element").clone().appendTo("targetContainer"); |
Set text | $("element").text("some text"); |
Set html | $("element").html("<span>some text</span>"); |
Set attribute | $("element").prop("disabled", true); |
Add class | $("element").addClass("someClass"); |
Remove class | $("element").removeClass("someClass"); |
Set style | $("element").css("color", "blue"); |
Add event listener | $("element").on("input", handler); |