Found 766 Articles for JQuery

What is the difference between jQuery.html( ) and jQuery.append( ) methods in jQuery?

David Meador
Updated on 09-Dec-2019 11:05:28

148 Views

jQuery.html() methodThe html() method gets the html contents (innerHTML) of the first matched element. This property is not available on XML documents.ExampleYou can try to run the following code to learn how to work with jQuery.html() method in jQuery:Live Demo           jQuery html() method                          $(document).ready(function() {             $("div").click(function () {                var content = $(this).html();                $("#result").html(content);             });   ... Read More

What is the difference between jQuery.map() and jQuery.each() Functions in jQuery?

David Meador
Updated on 09-Dec-2019 11:12:13

210 Views

jQuery map functionThe map method translates a set of elements in the jQuery object into another set of values in a jQuery array which may, or may not contain elements.ExampleYou can try to run the following code to learn how to work with jQuery.map() method:Live Demo           jQuery Map Method                              $(document).ready(function(){                         var mappedItems = $("li").map(function (index) {                var replacement = ... Read More

How to traverse Data Object Model (DOM) nodes using jQuery?

David Meador
Updated on 18-Dec-2019 07:11:56

217 Views

jQuery traversing is used to find elements based on what is their relation twith other elements. You need to begin with one selection and move ahead till you the reach the elements you want.jQuery is a very powerful tool which provides a variety of DOM traversal methods to help us select elements in a document randomly as well as in sequential method.Let’s filter out the elements by traversing. The filter( selector ) method can be used to filter out all elements from the set of matched elements that do not match the specified selector(s).ExampleThe selector can be written using any ... Read More

What is the difference between jQuery.map() and jQuery.grep() Functions in jQuery?

David Meador
Updated on 17-Dec-2019 10:21:43

337 Views

The jQuery map function translates a set of elements in the jQuery object into another set of values in a jQuery array which may, or may not contain elements. The grep() function is used to find an element of an array. The difference is we use $.grep to filter an array and $.map to apply a function to each item in the array.jQuery map functionThe map method translates a set of elements in the jQuery object into another set of values in a jQuery array which may, or may not contain elements.The following are the parameters of jQuery.map() method:callback − ... Read More

How to filter object array based on attributes in jQuery?

David Meador
Updated on 18-Dec-2019 07:10:59

1K+ Views

To filter object array based on attributes in jQuery, use the map() method with JSON.ExampleYou can try to run the following code to learn how to filter object array based on attributes in jQuery,Live Demo $(document).ready(function(){    $(document).ready(function(){     var json ={"DEPARTMENT": [             {                 "id":"1",                 "deptemp":"840",                 "shares":"1100",                           },             {                 "id":"2",                 "deptemp":"1010",                 "shares":"1900",                   }, {                 "id":"1",                 "deptemp":"350",                 "shares":"510",             },             {                 "id":"2",                 "deptemp":"575",                 "shares":"1900",             }]};            json.DEPARTMENT = $.map(json.DEPARTMENT,function(val,key) {               if(Number(val.deptemp) = 500) return val;            });         for(var i in json.DEPARTMENT)        $("p").html("Department Employees: "+json.DEPARTMENT[i].deptemp+" ,  Shares:"+json.DEPARTMENT[i].shares)     }); });

What is the jQuery destructive method end()?

David Meador
Updated on 09-Dec-2019 10:00:12

181 Views

The jQuery end() method reverts the most recent destructive operation, changing the set of matched elements to its previous state right before the destructive operation.This is how you can use it,operations.end()ExampleYou can try to run the following code to learn about jQuery destructive method end(),Live Demo           jQuery end() function                              $(document).ready(function(){             $("p").find("span").end().css("border", "4px red solid");          });                              p{             margin:5px;             padding:5px;          }                         Hello World!        

What is the difference between Grep and Filter in jQuery?

David Meador
Updated on 09-Dec-2019 09:58:26

692 Views

The grep() method finds an element and the filter() method returns elements matching a specific criteria.jQuery grep functionExampleThe grep() function is used to find an element of an array. You can try to run the following code to learn how to work with grep(), Live Demo   jQuery grep() function     div {     color: blue;   }   p {     color: red;     margin: 0;   }       var arr1 = [ 1, 7, 4, 8, 6, 1, 9, 5, 3, 7, ... Read More

What does the .end() function do in jQuery?

Amit D
Updated on 09-Dec-2019 10:01:22

107 Views

The end() method reverts the most recent destructive operation, changing the set of matched elements to its previous state right before the destructive operation.ExampleYou can try to run the following code to learn how to work with end function in jQuery:Live Demo           jQuery end() function                              $(document).ready(function(){             $("p").find("span").end().css("border", "2px blue solid");          });                              p{             margin:10px;             padding:10px;          }                         Hello World!        

What is the difference between jQuery.offsetParent( ) and jQuery.parent() methods in jQuery?

Amit D
Updated on 14-Feb-2020 07:28:47

197 Views

jQuery.offsetParent()The offsetParent() method returns a jQuery collection with the positioned parent of the first matched element.This is the first parent of the element that has position (as in relative or absolute). This method only works with visible elements.ExampleYou can try to run the following code to learn how to work with jQuery.offsetParent() in jQuery:Live Demo           jQuery offsetParent() method                              $(document).ready(function() {                         $("div").click(function () {       ... Read More

How to use jQuery.closest() method with class selector?

Amit D
Updated on 09-Dec-2019 10:15:59

3K+ Views

The closest() method begins with the current element and returns only the first ancestors matching the passed expression. This returned jQuery object has zero or one element. Using the class selector is easy and let us see how to use it below.ExampleYou can try to run the following code to learn how to use jQuery.closest() method with class selector:Live Demo .myclass * {     display: block;     border: 2px solid blue;     color: red;     padding: 5px;     margin:10px; }   $(document).ready(function(){     $("span").closest(".one").css({"color": "maroon", "border": "5px solid ... Read More

Advertisements