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
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
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
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 −
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP