Found 10711 Articles for Web Development

How to redirect to another webpage using JavaScript?

Ramu Prasad
Updated on 20-Apr-2022 12:40:56

18K+ Views

The window.location object contains the current location or URL information. We can redirect the users to another webpage using the properties of this object. window.location can be written without the prefix window.We use the following properties of the window.location object to redirect the users to another webpage −window.location.href- it returns the URL (href) of the current page.window.location.replace()- it replaces the current document with new document.window.location.assign() loads a new document.The syntaxes below are used to redirect to another web page. We omit the window prefix and use only location in all the program examples. You can try running the programs using ... Read More

Which equals operator (== vs ===) should be used in JavaScript comparisons

Sravani S
Updated on 12-Sep-2019 07:10:20

85 Views

Double equals (==) is abstract equality comparison operator, which transforms the operands to the same type before making the comparison.For example,4 == 4     // true '4' == 4   // true 4 == '4'   // true 0 == false // trueTriple equals (===) are strict equality comparison operator, which returns false for different types and different content.For example,4 === 4     // true 4 === '4'   // false var v1 = {'value': 'key'}; var v2 = {'value': 'key'}; v1 === v2   //false

Using CSS3 in SAP BSP application without using DOCTYPE tag

Amit Sharma
Updated on 30-Jul-2019 22:30:20

163 Views

To add a DOCTYPE tag without changing code of your BSP application, you can try using in Web Server, JQuery, or other UI libraries.There are various other libraries that you can search for as a replacement for CSS3 and they have their own advantage. I have used JQuery UI, Wijmo or Modernizer.

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

How to check if onClick exists on element in jQuery?

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

505 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 do I remove a property from a JavaScript object?

V Jyothi
Updated on 16-Jun-2020 06:21:09

119 Views

To remove a property from a JavaScript object, use the delete keyword. You can try to run the following code to learn how to remove a propertyExampleLive Demo                          var cricketer = {             name:"Amit",             rank:1,             points: 150          };          delete cricketer.rank;          document.getElementById("demo").innerHTML =             cricketer.name + " has " + cricketer.rank + " rank.";          

How to check if event exists on element in jQuery?

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

3K+ 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