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 to remove all style attributes using jQuery?
To remove an attribute from each tag using jQuery, use the removeAttr() method and use the Universal Selector. Let us see how to use the method to remove all style attribute. Use the universal selector also to select all the elements.You can try to run the following code to learn how to remove all style attributes using jQuery −Example $(document).ready(function(){ $("button").click(function(){ $("h1").removeAttr("style"); }); }); This is heading This is demo text. This is heading This is demo text. Remove Click above to remove style attribute from all h1 elements.
Read MoreHow to add and remove HTML attributes with jQuery?
To add and remove HTML attributes with jQuery, use the addClass() and removeClass() method.You can try to run the following code to add and remove HTML attributes with jQuery −Example jQuery Example $(document).ready(function(){ $( '#add' ).click( function () { $('#page_navigation1').addClass( 'blue-class' ); }); $( '#remove' ).click( function () { $('#page_navigation1').removeClass( 'blue-class' ); }); }); .blue-class { background-color: blue; font-size: 30px; } Demo Add Remove
Read MoreHow should I initialize jQuery in a web page?
To initialize jQuery in a web easy is quite easy. You can try to run the following code to learn how to initialize jQuery in a web page. We’re using Google CDN to add jQuery. Microsoft CDN is also available for the same purpose of adding jQuery library to HTML.Example jQuery Function $(document).ready(function() { $("div").click(function() {alert("Welcome to Tutorialspoint!");}); }); Click on this to see a dialogue box.
Read MoreIs it possible to use $(this) and universal selector (*) with jQuery?
Yes, it is possible to use $(this) and universal selector (*) with jQuery. Let’s see how to do it. You can try to run the following code to learn how to use this and universal selector with jQuery:Example jQuery Universal Selector $(document).ready(function() { $('*', this).css("background-color", "yellow"); }); This is first division of the DOM. This is second division of the DOM.
Read MoreHow to select a single element which matches the given ID using jQuery?
To select a single element which matches with the given ID using jQuery, use the element id selector. Here’s how,$('#elementid')You can try to run the following code to learn how to select a single element which matches with the given ID using jQuery −Example Selector Example $(document).ready(function() { /* This would select second division only*/ $("#div2").css("background-color", "yellow"); }); This is first division of the DOM. This is second division of the DOM. This is third division of the DOM
Read MoreHow to get an attribute value in jQuery?
To get an attribute value in jQuery is quite easy. For this, use the jQuery attr() method. You can try to run the following code to learn how to get an attribute value in jQuery −Example jQuery Example $(document).ready(function(){ $("button").click(function(){ alert($("img").attr("height")); }); }); Get the height
Read MoreHow to get the value of src attribute in jQuery?
To get the value of src attribute in jQuery is quite easy. We will get the src attribute of the img tag. This attribute has the URL of the image. Let’s first see how we can add jQuery −You can try to run the following code to learn how to get the value of src attribute in jQuery −Example Selector Example $(document).ready(function() { alert($('#myimg').attr('src')); }); Logo
Read MoreHow to change the value of an attribute using jQuery?
The jQuery attr() method is used to get the value of an attribute. It can also be used to change the value. In the example, we will change the attribute value tutorialspoint.com to tutorialspoint.com/java.You can try to run the following code to learn how to change the value of an attribute using jQuery −Example Selector Example $(document).ready(function(){ $("button").click(function(){ $("#tpoint").attr("href", "https://www.tutorialspoint.com/java"); }); }); tutorialspoint.com Change attribute value The value of above link will change on clicking the above button. Check before and after clicking the link.
Read MoreHow to add and remove a class to an anchor tag with jQuery?
To add and remove a class to an anchor tag, use the toggleClass. Using it you can add and remove a class on a click.You can try to run the following code to learn how to add and remove a class to an anchor tag with jQuery −Example $(document).ready(function(){ $("#mylink").click(function (e) { e.preventDefault(); $(this).toggleClass("selected"); }); }); .selected { color: red; } Click me The above will add and remove class (change color) on click.
Read MoreHow to add a title in anchor tag using jQuery?
To add a title in anchor tag in jQuery, use the prop() method. The prop() method is used to set properties and values of the selected elements.You can try to run the following code to learn how to add a title in anchor tag using jQuery −Example $(document).ready(function(){ $("#button1").click(function(){ $('.myClass').prop('title', 'This is your new title'); var myTitle = $('.myClass').prop('title'); alert(myTitle); }); }); Get Title
Read More