Found 730 Articles for JQuery

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

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

Which is the best tutorial site to learn jQuery?

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

149 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

223 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

867 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

How to check if onClick exists on element in jQuery?

ARPIT ANAND
Updated on 14-Feb-2020 08:01:05

804 Views

These codes might help you −$('body').click(function(){ alert('test' )}) var foo = $.data( $('body').get(0), 'events' ).click // you can query $.data( object, 'events' ) and get an object back, then see what events are attached to it.  $.each( foo, function(i,o) {     alert(i) // guid of the event     alert(o) // the function definition of the event handler });

How to check if event exists on element in jQuery?

Kristi Castro
Updated on 19-Jun-2020 12:47:44

4K+ Views

To check if event exists on element in jQuery, check for the existing events on the element. Here, I have set the div −   This is demo text. Click here! When you click div, then the alert generates which I have set using the div id:$("#demo").click(function() {   alert("Does event exists? - "+hasEvents); });You can try to run the following code to check if event exists −ExampleLive Demo               $(document).ready(function(){       $("#demo").click(function() {         alert("Does event exists? - "+hasEvents);      });      var events = $._data(document.getElementById('demo'), "events");      var hasEvents = (events != null);    });         This is demo text. Click here!

Advertisements