Found 766 Articles for JQuery

How to Scroll to the top of the page using JavaScript/ jQuery?

Anjana
Updated on 16-Jun-2020 08:16:43

169 Views

ExampleLive Demo                    $("a").click(function() {             $("html, body").animate({ scrollTop: 0 }, "slow");             return false;          });             TOP OF PAGE             This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is ... Read More

Why would a jQuery variable start with a dollar sign?

Johar Ali
Updated on 13-Jun-2020 13:14:27

264 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);

Where should jQuery code go in header or footer?

Ali
Ali
Updated on 20-Feb-2020 07:01:23

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    

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

Ali
Ali
Updated on 20-Feb-2020 05:23:20

6K+ 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”) });

Which is the best tutorial site to learn jQuery?

Srinivas Gorla
Updated on 16-Jun-2020 07:42:22

81 Views

jQuery is a fast and concise JavaScript Library created by a John Resig in 2006 with a nice motto − Write less, do more.jQuery simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.Here is the list of important core features supported by jQuery:DOM manipulation − jQuery made it easy to select a DOM elements, traverse them and modifying their content by using a cross-browser open source selector engine called as Sizzle.Event handling − The jQuery offers an elegant way to capture a wide variety of events, such as a user clicking on a link, without ... Read More

SAP UI5 framework and comparison with JQuesry and Backbone, Angular, etc.

karthikeya Boyini
Updated on 15-Jun-2020 07:32:18

127 Views

The SAPUI5 framework is the original version of the SAP toolkit which was released initially. This version of the toolkit is a proprietary version. Later SAP released an Open source version of it named OpenUI5. Functionally it is almost equivalent in terms of basic operations negating few features but overall sufficient enough as a UI framework.This UI5 framework (applies to both SAPUI5 and OpenUI5) is capable of dispensing all major tasks expected from a full-fledged UI framework. It supports following features:Model View Controller architectureRouting engineModules with the help of module loadersFull data binding either in XML, JSON or using web servicesCulture ... Read More

Where do we use $.extend() method in jQuery?

David Meador
Updated on 15-Jun-2020 13:18:40

1K+ Views

The jQuery.extend() method is used to merge contents of two or more objects together. The object is merged into the first object. You can try to run the following code to learn how to use extend() method −ExampleLive Demo $(document).ready(function() {   $("#button1").click(function() {     var obj1 = {       maths: 60,       history: {pages: 150,price: 400,lessons: 30},       science: 120     };     var obj2 = {       history: { price: 150, lessons: 24 },       economics: 250     };     $.extend(true, obj1, obj2);     $("#demo").append(JSON.stringify(obj1));    }); });    Result    

When to use $(document).ready() and when $(window).load() in jQuery?

Alex Onsman
Updated on 30-Jul-2019 22:30:20

728 Views

$(window).load()Use $(window).load(), when you want the code inside it to run only once the entire page is ready (not only DOM).  It executes when the page is fully loaded, including frames, objects and imagesNote: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.$(document).ready()Use the  $(document).ready() method when you want the code inside it to run once the page DOM is ready to execute JavaScript code.

How to iterate over arrays and objects in jQuery?

David Meador
Updated on 15-Jun-2020 13:17:04

1K+ Views

To iterate over arrays and objects in jQuery, use the jQuery forEach() loop. You can try to run the following code to learn how to iterate over arrays and objects −ExampleLive Demo $(document).ready(function(){   $("#button1").click(function(){     var arr = [{subject: "Maths", id:3}, {subject: "History", id:7}];     arr.forEach(function(el, index) {       alert(el.id+" "+el.subject);     });   }); });   Result

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

Ricky Barnes
Updated on 15-Jun-2020 13:44:33

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 −ExampleLive Demo $(document).ready(function(){   $("#button1").click(function(){     var myStr = "  Hello World    ";     myStr = jQuery.trim(myStr);     alert(myStr);   }); }); Trim

Advertisements