Front End Technology Articles

Page 649 of 652

How to trim a string using $.trim() in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 15-Jun-2020 3K+ Views

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 More

Why would a jQuery variable start with a dollar sign?

Johar Ali
Johar Ali
Updated on 13-Jun-2020 416 Views

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 More

How can I alter the color of an HTML5 canvas element using jQuery?

Daniol Thomas
Daniol Thomas
Updated on 04-Mar-2020 340 Views

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 More

Where should jQuery code go in header or footer?

Ali
Ali
Updated on 20-Feb-2020 2K+ Views

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 More

How do I put a jQuery code in an external .js file?

Ali
Ali
Updated on 20-Feb-2020 7K+ Views

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 More

How to include multiple js files using jQuery $.getScript() method?

David Meador
David Meador
Updated on 17-Feb-2020 771 Views

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 More

What is the difference between jQuery.load() and jQuery.ajax() methods in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 17-Feb-2020 641 Views

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 More

What is the difference between jQuery.post() and jQuery.get() methods in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 17-Feb-2020 351 Views

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 More

Angular 2 Vs Angular 1: Lets Checkout the Changes

karthikeya Boyini
karthikeya Boyini
Updated on 20-Jan-2020 287 Views

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 More

Top Bootstrap UI Tools

Sharon Christine
Sharon Christine
Updated on 16-Jan-2020 402 Views

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
Showing 6481–6490 of 6,519 articles
Advertisements