Found 10711 Articles for Web Development

How to get current URL in jQuery?

Arnab Chakraborty
Updated on 22-Jun-2020 07:56:43

3K+ Views

For getting the current URL you can use attr() method or window.location.Example url               $(document).ready(function () {          $("button").click(function () {             alert($(location).attr('href'));             alert(window.location);          });       });     Display URL

How to get current URL in JavaScript?

Arnab Chakraborty
Updated on 21-Jun-2020 14:20:51

444 Views

The window.location object can be used to get the current URL.window.location.href returns the href(URL) of the current page.I am using these code in my MVC projet.Example                                          var iid=document.getElementById("dd");         alert(window.location.href);       iid.innerHTML = "URL is" + window.location.href;    

How can I know which radio button is selected via jQuery?

Arnab Chakraborty
Updated on 23-Jun-2020 09:48:08

291 Views

The jQuery: checked selector can be used in conjugation with the val() to find the value of certain radio button as,$('input[name=radioName]:checked').val()In your query this can be implemented as −Example Live Demo               $(document).ready(function() {          $("input[type='button']").click(function() {             var radioValue = $("input[name='q1']:checked").val();             if(radioValue) {                alert("You select - " + radioValue);             }          });       });            Select a number:       1       2       3    

How can I remove all child elements of a DOM node in JavaScript?

Arnab Chakraborty
Updated on 11-Aug-2022 10:45:43

11K+ Views

Suppose you are building a web app that manages the data of daily tasks, the user inserts the task and a list of tasks gets formed. But at some point in time, the user wants to remove all the tasks from the list and wants to make the list empty. So, as a developer, you should know how to remove all the child elements from the DOM node. To remove all the elements from the DOM node we have the following approaches. By iterating the DOM nodes and using the removeChild method. By Erasing the innerHTML value to a ... Read More

How to select ALL children (in any level) from a parent in jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:35:38

771 Views

To select all children from a parent in jQuery, use the find() method. You can try to run the following code to select ALL children in any level −ExampleLive Demo        .myclass * {      display: block;      border: 2px solid lightgrey;      color: lightgrey;      padding: 5px;      margin: 15px;    }         $(document).ready(function(){     $('ul').find('*').css({"color": "red", "border": "2px solid green"});   });     div - great-grandparent   ul    li- child - level 1      ul- child - level 2        li- child - level 3        li- child - level 3                  

Why do we use JSON.stringify() method in jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:32:07

418 Views

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Use the JSON.stringify() method to convert a JavaScript object into a string.You can try to run the following code to learn how to work with JSON.stringify() method −ExampleLive Demo JSON string is created above   var v = { "name":"Amit", "Rank":1, "city":"India"};   var newJSON = JSON.stringify(v);   document.getElementById("test").innerHTML = newJSON;

What e.preventDefault() method really does in jQuery?

Arnab Chakraborty
Updated on 23-Jun-2020 11:31:54

3K+ Views

The preventDefault() method stops the default action of a selected element from happening by a user. This method does not accept any parameter and works in two ways:It prevents a link from following the URL so that the browser can't go another page.It prevents a submit button from submitting a form.Example               $(document).ready(function() {          $("a").click(function(event) {             event.preventDefault();          });       });        Tutorialspoint.com    Click the link and it wont work.

How to increase the duration of jQuery effects?

Kristi Castro
Updated on 20-Jun-2020 07:31:03

226 Views

To increase the duration of jQuery effects, set the optional speed parameter. The values include, slow, fast, milliseconds, etc. The fast value is used to increase the duration.Let us see an example with fadeIn() jQuery method. The fadeIn( ) method fades in all matched elements by adjusting their opacity and firing an optional callback after completion. Here is the description of all the parameters used by this method −speed − A string representing one of the three predefined speeds ("slow", "def", or "fast") or the number of milliseconds to run the animation (e.g. 1000).callback − This is optional parameter representing ... Read More

How do I use jQuery effects?

Arnab Chakraborty
Updated on 22-Jun-2020 08:19:58

118 Views

For hiding and showing the div, you can use hide and show method.For hiding$('#id1').hide();For showing$('#id1').show();Example showhide                 $(document).ready(function () {          $('#btn1').click(function () {             $('#id1').hide();          });          $('#btn2').click(function () {             $('#id1').show();          });       });        I Am A Simple Paragraph    Hide    Show MethodDescriptionanimate()Runs a custom animation on the selected elementsclearQueue()Removes all remaining queued functions ... Read More

How to adjust the height of iframe based on the loaded content using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:25:20

2K+ Views

To adjust the height of iframe, use the jQuery height() method. You can try to run the following code to adjust height of iframe dynamically on button click:ExampleLive Demo                 $(document).ready(function(){         $("button").click(function(){           $("iframe").height(300);         });       });             Change Height

Advertisements