jQuery get() Method

AmitDiwan
Updated on 31-Dec-2019 09:33:09

144 Views

The get() method in jQuery is used to get the DOM elements matched by the selector.SyntaxThe syntax is as follows −$(selector).get(index)Above, the index specifies which of the matching elements to get.Let us now see an example to implement the jQuery get() method −Example Live Demo    $(document).ready(function(){       $("button").click(function(){          var res = $("li").get(2);          $("span").text(res.innerHTML);       });    }); Devices TV Laptop Headphone Earphone SSD 3rd li element OutputThis will produce the following output −Now, click on the button −ExampleLet ... Read More

jQuery each() Method

AmitDiwan
Updated on 31-Dec-2019 09:29:42

193 Views

The each() method in jQuery is used to execute a function for each matched element.SyntaxThe syntax is as follows −$(selector).each(function(index, ele))Above, the index is the position of the selector, whereas ele is the current element.Let us now see an example to implement the jQuery each() method −Example Live Demo    $(document).ready(function(){       $("button").click(function(){          $("li").each(function(){             alert($(this).text())          });       });    }); Devices TV Laptop Headphone Earphone SSD Get each element OutputThis will produce the ... Read More

Comparison Between AND and && Operator in PHP

Alok Prasad
Updated on 31-Dec-2019 09:28:32

547 Views

PHP offers incredible operators to perform operations such as arithmetic, assignment, comparison and many more ...In this article, more importance will be laid on logical operators "&&" and "AND" and will study how they can be utilized based on their precedence. Logical operators "&&" and "AND" produce true-or-false as results, and therefore these are also known as Boolean operators. Before diving into deep let's learn what is "AND" operator? "AND" operator returns true if and only if both the conditions are true. Let's take an example to demonstrate "AND" operator.ExampleOutput:TrueExplanation:Since variable $val1 = 20 and $val2 = 50, the condition $val1 ... Read More

jQuery Length Property

AmitDiwan
Updated on 31-Dec-2019 09:25:52

357 Views

The length property in jQuery is used to get the number of elements in the jQuery object.SyntaxThe syntax is as follows −$(selector).lengthExampleLet us now see an example to implement the jQuery length property − Live Demo    $(document).ready(function(){       $("button").click(function(){          document.getElementById("demo").innerHTML = "Count = " + $("li").length       });    }); Devices TV Laptop Headphone Earphone SSD Count of li OutputThis will produce the following output −Click “Count of li” to get the number of li elements −

jQuery Traversing Ancestors

AmitDiwan
Updated on 31-Dec-2019 09:23:39

276 Views

To traverse and find ancestors of an element, jQuery has the following methods: parent(), parents() and parentsUntil()−parent() methodThe parent() method in jQuery is used to return the direct parent element of the selected element. Let us see an example −Example Live Demo div {    width:600px; } .demo * {    display: block;    border: 2px solid yellow;    color: blue;    padding: 10px;    margin: 10px; }    $(document).ready(function(){       $("span").parent().css({"color": "blue", "border": "3px dashed blue"});    }); great-great-grandparent great-grandparent grandparent parent span OutputThis will produce ... Read More

jQuery toArray Method

AmitDiwan
Updated on 31-Dec-2019 09:14:34

157 Views

The toArray() method in jQuery is used to get all the DOM elements contained in the jQuery set, as an arraySyntaxThe syntax is as follows −$(selector).toArray()Let us now see an example to implement the jQuery toArray() method −Example Live Demo    $(document).ready(function(){       $("button").click(function(){          var arr = $("p").toArray()          for (var k = 0; i< arr.length; k++) {             alert(arr[k].innerHTML);          }       });    }); Devices This is demo text 1. This is demo text ... Read More

jQuery is() Method

AmitDiwan
Updated on 31-Dec-2019 09:11:50

304 Views

The is() method in jQuery is used to check whether one of the selected elements matches the value in parameter selectorEle.SyntaxThe syntax is as follows −$(selector).is(selectorElement, func(index, element))Above, selectorEle is a selector expression, element or jQuery object to match with the current set of the element. The func parameter is used to specify a function to run for the group of selected elements.ExampleLet us now see an example to implement the jQuery is() method − Live Demo div {    width:600px; } .demo * {    display: block;    border: 2px solid yellow;    color: blue;    padding: ... Read More

Getters and Setters Methods in PHP

Alok Prasad
Updated on 31-Dec-2019 08:57:06

15K+ Views

In this article, we learn the best way to create getter and setter strategies in PHP. Getter and setter strategies are utilized when we need to restrict the direct access to the variables by end-users. Getters and setters are methods used to define or retrieve the values of variables, normally private ones.Just as the name suggests, a getter method is a technique that gets or recovers the value of an object. Also, a setter method is a technique that sets the value of an object.ExampleLet's understand the use of getter and setter methods through an example.Output:PHP Error Cannot access private ... Read More

Namespace Keyword in PHP

Alok Prasad
Updated on 31-Dec-2019 08:53:49

369 Views

In this article, we are going to learn about namespace in PHP. In PHP when we are creating large applications or when integrating third-party applications/library then there may be chances of collision between class names, function names. So to avoid these problems PHP "Namespaces" provide a way in which to group related classes, interfaces, functions and constants.Let's see the syntax of declaring namespace below.SyntaxIn the PHP world, namespaces are intended to take care of two issues that creators of libraries and applications experience when making re-usable code components, Those are:1.Name impact between code you create, and internal PHP classes/functions/constants or ... Read More

Display Two Decimals in MySQL and PHP

Arjun Thakur
Updated on 31-Dec-2019 08:52:20

360 Views

To display two decimals, use number_format(). Let us first write the PHP code for the same. We have first declared two variables are initialized −$number1=10.3423; $number2=10;Now, display the two decimals using the number_format() function −$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);ExampleFollowing is the example −OutputFollowing is the snapshot of PHP code −10.34 10.00

Advertisements