JQuery coding


1. Performing some scripts after the DOM is ready.
	$( document ).ready(function() {
		console.log( "I am ready!" );
		console.log( "I am ready!" );
2. How to get a value of text box or select combo box using the ID or class
	//Sample using textbox
	//Sample using select combo box
3. How to add and remove a css class.
	//removing a class
	//adding a class
4. How to check if a checkbox is checked.
	//check if a checkbox is ticked
5. How to check if an object is visible.
	//check if an object is visible
6. How to check if an object exists.
	//check if an object is exists
	if($("#myObject").length > 0){
7. How to set an attribute to a html object.
	//set an data attribute to an object
	$("#myID").attr("data-id", "1");
8. How to set a specific style to an object.
	//set a height of an object to 100px
	$("#myID").css("height", "100px");
9. How to hide or show an object.
	//hide an object
	//show an object
10. How to get an object based on partial id.
	//get an object contains any keyword myID
	//get an object where the ID is end up with keyword myID
11. How to empty items in select combo box and append new items.
	//empty combo box items
	//add a new item option into combo box
	$("#cboCountry").append("<option value='AU'>Australia</option>");
12. How to bind and unbind an event to a button.
	//attach event click
	$("#btnSubmit").on("click", function(event){});
	//remove event click
13. How to get a href link value using attr keyword.
14. How to disable or enable a html input button or text box.
	//disable button or text box
	$("#myButton").attr("disabled", true);
	$("#txtName").attr("disabled", true);
	//enable button or text box
	$("#myButton").attr("disabled", false);
	$("#txtName").attr("disabled", false);
15. Getting on input text only from a html DOM.
	$("input [type=text]");
16. Attach multiple events to a button.
	$("#btnSubmit").bind("blur keypress", function (event){
17. Check if a li tag contains specific word and hide it.
	$("li:contains('my word')).hide();
18. For loop of JSON object in JQuery.
	var obj = { banana: 1, apple: 2, orange: 3, grape: 4, mango: 5 };
	jQuery.each( arr, function( i, val ) {
19. Avoiding conflict with other script libraries that use JQuery.
	var $jq = jQuery.noConflict();
20. Change the background color for even and odd position only for ul li list.
	//for even position
	$("li").filter( ":even" ).css("background-color", "blue");
	//for odd position
	$("li").filter( ":odd" ).css("background-color", "red");
21. Remove an element of DOM.
	//This will remove any div tag that contains align css class.
	$( "div.align" ).remove();

More tips will be added on the list, if you have any tips that need to be added, please adds it to the following comment.

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

escort kutahya escort bornova escort beylikduzu escort amasya escort diyarbakir