Found 10711 Articles for Web Development

What is the difference between jQuery.hide() and jQuery.remove() methods in jQuery?

David Meador
Updated on 10-Dec-2019 07:23:42

342 Views

jQuery.hide()If you want to hide an element, then use the hide() method to hide the selected element.ExampleYou can try to run the following code to learn how to work with jQuery.hide() method using jQuery:Live Demo $(document).ready(function(){     $(".button1").click(function(){         $("p").hide();     });     $(".button2").click(function(){         $("p").show();     }); }); Hide the element Show the element This is demo text. jQuery.remove()The remove() method will remove the selected elements, but it also includes the text and child nodes.ExampleYou can try to run ... Read More

How does jQuery.clone() method work in jQuery?

David Meador
Updated on 10-Dec-2019 07:26:02

124 Views

To clone an element using jQuery, use the jQuery.clone() method. The clone() method clones matched DOM Elements and select the clones.This is useful for moving copies of the elements to another location in the DOM.ExampleYou can try to run the following code to learn how to work with jQuery.clone() method in jQuery:Live Demo           jQuery clone() method                              $(document).ready(function() {             $("div").click(function () {                $(this).clone().insertAfter(this);             });          });                              .div {              margin:15px;              padding:15px;              border:4px solid #666;              width:90px;          }                             Click on any square below to see the result:                                  

How to duplicate a div using jQuery?

David Meador
Updated on 10-Dec-2019 07:27:38

2K+ Views

To duplicate a div in jQuery, use the jQuery clone() method.ExampleYou can try to run the following code to learn how to duplicate a div using jQuery:Live Demo $(document).ready(function(){    $("button").click(function(){       $("div").clone().appendTo("body");    }); }); This is a text Clone div and append

How to clone an element using jQuery?

David Meador
Updated on 10-Dec-2019 07:30:02

5K+ Views

To clone an element using jQuery, use the jQuery.clone() method. The clone() method clones matched DOM Elements and select the clones.This is useful for moving copies of the elements to another location in the DOM.ExampleYou can try to run the following code to learn how to clone an element using jQuery:Live Demo           jQuery clone() method                              $(document).ready(function() {             $("div").click(function () {                $(this).clone().insertAfter(this);             });          });                              .div {              margin:10px;              padding:12px;              border:2px solid #666;              width:60px;          }                             Click on any square below to see the result:                                          

How to change CSS using jQuery?

David Meador
Updated on 10-Dec-2019 07:44:10

573 Views

To change CSS using jQuery, use the jQuery css() method.ExampleYou can try to run the following code to change CSS using jQuery:Live Demo $(document).ready(function(){     $("h2").css("backgroundColor", "red");     $("#myid").css({         "backgroundColor": "gray",         "color": "white"});     $(".myclass").css("border", "2px solid black"); }); Heading 2 This is some text. This is some text.

How to find left position of element in horizontal scroll container using jQuery?

David Meador
Updated on 10-Dec-2019 07:42:23

1K+ Views

To find the left position of element in horizontal scroll container using jQuery, use the animate() function with the scrollLeft() function.ExampleYou can try to run the following code to learn how to find left position of an element in horizontal scroll container:Live Demo $(document).ready(function() {        var scrollArea = $('#box');    var toScroll = $('#box .myclass');    function myScroll() {      toScroll.each(function() {         var self = $(this);         $(this).css('cursor', 'pointer');         $(this).on('click', function () {             var ... Read More

How to create a div element in jQuery?

Nizam Techs
Updated on 12-Jun-2020 13:15:44

663 Views

They are many way to add a div using jquery , but as the requirement says  on click of any square we have to addd a div.  The following code below will help in adding a div on click Click on any square below to see the result                               $(".div").on("click",function(){ $('#box').append(   $('')     .attr("id", "newDiv1")     .addClass("div")     .append("")       .text("hello world")     ); });

How to insert element as a last child using jQuery?

David Meador
Updated on 10-Dec-2019 07:06:22

4K+ Views

To insert element as a last child using jQuery, use the append() method. The append( content ) method appends content to the inside of every matched element.ExampleYou can try to run the following code to learn how to insert element as a last child using jQuery:Live Demo           jQuery Example                              var x = 0;          $(document).ready(function() {             $('.add').on('click', function (event) {         var html = "demo text " + x++ + "";         $("#parent-div").append(html);     });          });                          .div{             margin:10px;             padding:12px;             border:2px solid #F38B00;             width:60px;          }                                 Hello World                

How to insert element as a first child using jQuery?

David Meador
Updated on 10-Dec-2019 07:09:54

6K+ Views

To insert element as a first child using jQuery, use the prepend() method. The prepend( content ) method prepends content to the inside of every matched element.ExampleYou can try to run the following code to learn how to insert element as a first child using jQuery:Live Demo           jQuery Example                              var x = 0;          $(document).ready(function() {             $('.add').on('click', function (event) {                var html = "demo text " + x++ + "";                $("#parent-div").prepend(html);             });          });                              .div {             margin:10px;             padding:12px;             border:2px solid #F38B00;             width:60px;          }                   Hello World    

How to insert content after each of the matched elements using jQuery?

David Meador
Updated on 17-Dec-2019 07:12:28

130 Views

To insert content after each of the matched elements using jQuery, use the after() method.The after( content ) method inserts content after each of the matched elements. Here is the description of all the parameters used by this method −content − Content to insert after each target. This could be HTML or Text contentExampleYou can try to run the following code to learn how to insert content after each of the matched elements:Live Demo           jQuery after() method                              $(document).ready(function() { ... Read More

Advertisements