Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Front End Technology Articles
Page 649 of 652
How to trim a string using $.trim() in jQuery?
To trim a string in jQuery, use the trim() method. It removes the spaces from starting and end of the string. The sample string I am using has spaces − var myStr = " Hello World "; Use the trim() method, jQuery.trim(myStr); The following is an example to trim a string in jQuery − Example $(document).ready(function(){ $("#button1").click(function(){ var myStr = " Hello World "; myStr = jQuery.trim(myStr); alert(myStr); }); }); Trim
Read MoreWhy would a jQuery variable start with a dollar sign?
When you will begin working about jQuery, you will get to know about the usage of the $ sign. A $ sign is used to define jQuery.jQuery variables begin with $ to distinguish them from a standard JavaScript object. Also, it is a convention. jQuery selectors start with the dollar sign and parentheses() − $.Let's take an Example −// jQuery object var $phone = $("#myphone"); // dom object var phone_el = $("#myphone").get(1);
Read MoreHow can I alter the color of an HTML5 canvas element using jQuery?
To alter the color of an HTML5 canvas, use −document.getElementById("ID").style.background = red;You can also try the following −var ctx = canvas.getContext('2d'); ctx.fillStyle = "#FF0000"; ctx.fill();
Read MoreWhere should jQuery code go in header or footer?
It’s always a good practice to add jQuery code in footer i.e. just before the closing tag. If you have not done that, then use the defer attribute.Use defer attribute so the web browser knows to download your scripts after the HTML downloaded −The defer attribute is used to specify that the script execution occurs when the page loads. It is useful only for external scripts and is a boolean attribute.ExampleThe following code shows how to use the defer attribute − The external file added will load later, since we're using defer
Read MoreHow do I put a jQuery code in an external .js file?
Create an external JavaScript file and add the jQuery code in it.ExampleLet’s say the name of the external file is demo.js. To add it in the HTML page, include it like the following − Hello Above we added jQuery using Google CDN and the external file was included after that.Add jQuery code in demo.js, since you wanted to place jQuery code −$(document).ready(function(){ alert(“amit”) });
Read MoreHow to include multiple js files using jQuery $.getScript() method?
To use multiple js files, use the same getScript(), which is used to add a single js file. We’re having result.js file with the following code snippet −function CheckJS(){ alert("This is JavaScript - File1"); }We’re having result2.js file with the following code snippet −function CheckJS(){ alert("This is JavaScript – File2"); }ExampleHere's the code snippet to add multiple js files. Here, we will call the function in the above 2 js files − ...
Read MoreWhat is the difference between jQuery.load() and jQuery.ajax() methods in jQuery?
jQuery ajax() methodThe jQuery.ajax( options ) method loads a remote page using an HTTP request. $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually.Here is the description of all the parameters used by this method −options − A set of key/value pairs that configure the Ajax request. All options are optional.Assuming we have the following HTML content in result.html file −THIS IS RESULT...ExampleThe following is an example showing the usage of this method. Here, we make use of success handler to ...
Read MoreWhat is the difference between jQuery.post() and jQuery.get() methods in jQuery?
jQuery post() methodThe jQuery.post( url, [data], [callback], [type] ) method loads a page from the server using a POST HTTP request.Assuming we have following PHP content in result.php file, ExampleThe following is the code snippet showing the usage of this method − $(document).ready(function() { ...
Read MoreAngular 2 Vs Angular 1: Lets Checkout the Changes
Since the inception of Angular JS, it has been widely used by many developers worldwide to build their applications. The JavaScript-based open source framework has become popular in developers community due to its great features such as simple and better way to manage MVC components, usage of JavaScript objects and many more.That is the Angular 1 with those great features which made Angular JS a popular and widely accepted framework. But as we know nothing is perfect, there is always scope for improvements, based on that philosophy now it’s time for Angular 2 which comes with many improved features.With its ...
Read MoreTop Bootstrap UI Tools
When looking at a website, the most attractive thing that catches the eye is its design and the placement of elements on the page. It looks easy to implement and appealing but the pain of designing is only known to a designer. The UI kits are available in the market which can help in reducing this pain by providing ready to use frameworks and layouts.Twitter Bootstrap is one of the most popular web framework for HTML5 and has proven to be the stable and most used framework. It is very easy to implement and understand. The twitter Bootstrap helps in ...
Read More