Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
How can I add an attribute into specific HTML tags in jQuery?
Use the attr() method to add an attribute into specific HTML tags in jQuery.ExampleYou can try to run the following code to learn how to add an attribute into specific HTML tags: $(document).ready(function(){ $(document).ready(function(){ $("button.button1").attr("myid", "myvalue"); $('button').on('click', function() { if (this.hasAttribute("myid")) { alert('True: The new attribute added successfully.') } else { alert('False') } }) }); }); Button 1
Read MoreWhat are generator functions in JavaScript?
Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code. Cancel asynchronous operations easily since execution can be paused anytime.Here’s the syntax; do not forget to add an asterisk after the “function” keyword. You can add an asterisk using any of the following −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}ExampleLet’s see how to use a generator function function* display() { var ...
Read MoreHow to use jQuery to get the value of HTML attribute of elements?
To get the value of html attribute, use the val() method.ExampleYou can try to run the following code to learn how to use jQuery to get the value of HTML attribute of elements: $(document).ready(function() { $("#buttonSet").click(function () { $("#buttonGet").removeAttr('disabled'); }); $("#buttonGet").click(function () { $("#result").html( $("#txtBox").val() + "" + $("input:radio[name=rd]:checked").val() ); }); }); Name Gender Male Female
Read MoreHow to set “checked” for a checkbox with jQuery?
Use the checked attribute to set the checkbox with jQuery. Also, the prop() method is used to get the property value.ExampleYou can try to run the following code to learn how to set checked for a checkbox: jQuery Example b { color: green; } Check/ Uncheck this checkbox $( "input" ).change(function() { var $input = $( this ); $( "p" ).html( ".attr( "checked" ): " + $input.attr( "checked" ) + "" + ".prop( "checked" ): " + $input.prop( "checked" ) + "" + ".is( ":checked" ): " + $input.is( ":checked" ) + "" ); }).change();
Read MoreHow do we use # in jQuery Attribute Selector?
To use # in jQuery attribute selector, include # under *= . This will find the attribute with #.ExampleYou can try to run the following code to learn how to use # in jQuery attribute selector: $(document).ready(function() { $( "div[myattr*='#']" ).css("background-color", "yellow"); }); Java HTML Ruby
Read MoreHow do we use jQuery Attribute selector with a period?
jQuery Attribute selector is used to select elements with the specified attribute and value. You can easily use it with a period (.) or a hash (#).ExampleYou can try to run the following code to learn how to use jQuery selector with a period: $(document).ready(function(){ $( "div[myattr*='.']" ).css("background-color", "yellow"); }); Java HTML Ruby
Read MoreHow do we use wildcard or regular expressions with a jQuery selector?
Wildcard or regular expressions can also be used with jQuery selector for id of element.ExampleYou can try to run the following code to use wildcard or regular expressions with jQuery selector: $(document).ready(function(){ $("[id^=sub]").css("background-color", "green"); }); Java HTML Ruby
Read MoreUsage of rest parameter and spread operator in JavaScript?
Rest ParameterWith rest parameter, you can represent a number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and precedes a parameter.Let’s see the following code snippet to define rest parameter − function addition(…numbers) { var res = 0; numbers.forEach(function (number) { res += number; }); ...
Read MoreWhat are the latest operators added to JavaScript?
The latest operators added to JavaScript are spread operator and rest.Rest operatorWith rest parameter, you can represent number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and preceds a parameter.ExampleLet’s see the following code snippet to define rest parameter function addition(…numbers) { var res = 0; numbers.forEach(function (number) { res += number; ...
Read MoreHow to use jQuery selector for the elements with an ID that ends with a given string?
To get the elements with an ID that ends with a given string, use attribute selector with $ character.ExampleYou can try to run the following code to learn how to to use jQuery selector for the elements with an ID that ends with a given string. Let’s say we are going for elements with an ID ending with the string “new1”. $(document).ready(function(){ $("[id$=new]").css("background-color", "yellow"); }); Java HTML Ruby
Read More