JavaScript | Miscellaneous Topics
To define a function in JavaScript, use
function function_name() {
}
The for .. in loop:-
for(let i in arr) {
console.log(i);
console.log("<br />");
}
To define constant variables in JavaScript use
The name variable's value cannot be changed.
const name = "Gaurav";
The name variable's value cannot be changed.
All JavaScript functions have one implicit object called arguments, which store all the parameters of the function, i.e.,
arguments[0] will return the first parameter from left to right.
arguments.length return the number of arguments passed to the function
arguments.length return the number of arguments passed to the function
FormData
If we want to send file(s) through AJAX we can use them FormData built-in class of JavaScript.
Just write
let file_upload = new FormData("<form_name>");
Just write
let file_upload = new FormData("<form_name>");
<div class="modal fade" role="dialog">
<div class ="modal-dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
</button>
<div class="modal-title">
Some title
</div>
</div>
<div class="modal-body">
Some body
</div>
<div class="modal-footer">
Some footer
</div>
<div>
</div>
Important Concepts
- hasClass method is used fopr checking if an HTML5 element specified bny a selection has a particular class in its class attribute
- To remove one of the many classes separated by a space in the class attribute of the HTML element, we use,
$("aselector').removeClass("show");
- To add a class, use
$("selector").addClass("show");
- <input type="radio" onclick="check(this.value)" />
The this variable represents the HTML element who has trigerred the event - A form tag contains an element[] property which describes the array representing a form's elements
- length property: The number of elements in a form
- Target: The window in which any results returned from the server are displayed
- JavaScript provides the facility to send the form data to an email address instead of submitting it to the server through CGI
- The HTML code for emailing a form's data to email address mailme@yahoo.com as given below
<form action="mailme@yahoo.com" method="POST" enctype="info" />
-
The resize event on the window object is called whenever the window size is altered.
$(window).resize(function(){});
-
When you are uploading file through AJAX, use the following two lines are required
content-type : false
process-data : false
-
To check if a checkbox or a radio button is checked or not , use
$("#checkall").is(":checked")
- The data type required for FormData() constructor is a form element in Document Object Tree (DOM)
The jQuery function for setting a boolean attribute use the following prop() method:-
$("select").prop("multiple");
- Adds functionality to select one or more select items in a dropdown box
$("input[type=checkbox]").prop("checked");
- Checks the checkbox
$("div").prop("content-editable");
- Makes the text inside a <div> editable
$("input[type=text]").prop("readonly");
- Makes an in-put text field uneditable
$("button").prop("disabled");
- Disables the button click functionality
$("option").prop("selected");
- Specifies which element in a dropdown box must be slected and displayed in the dropdown which is not opnened
$("input[type=text]").prop("autofocus");
- Makes the cursor move to the text field on page loading
$("form").prop("novalidate");
- Specifies not o do validation on input elemnts in HTML5 input elemnts
$("h2").prop("draggable');
- Allows the <h2> to be draggable
$("video").prop("controls');
- Allows to display all the controls for a video tag
Comments
Post a Comment