Front End Technology Articles - Page 650 of 652

How to add a title in anchor tag using jQuery?

Ricky Barnes
Updated on 13-Feb-2020 09:54:55

3K+ Views

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 −ExampleLive Demo                        $(document).ready(function(){          $("#button1").click(function(){             $('.myClass').prop('title', 'This is your new title');             var myTitle = $('.myClass').prop('title');             alert(myTitle);          });        });                                        Get Title          

How to add and remove a class to an anchor tag with jQuery?

Ricky Barnes
Updated on 13-Feb-2020 09:48:48

2K+ Views

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 −ExampleLive Demo                         $(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.    

How to change the value of an attribute using jQuery?

Ricky Barnes
Updated on 13-Feb-2020 09:46:57

8K+ Views

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 −ExampleLive Demo           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.    

How to get the value of src attribute in jQuery?

Amit D
Updated on 13-Feb-2020 09:43:51

5K+ Views

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 −ExampleLive Demo           Selector Example                      $(document).ready(function() {             alert($('#myimg').attr('src'));          });                     Logo          

How to get an attribute value in jQuery?

Amit D
Updated on 13-Feb-2020 09:40:41

2K+ Views

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 −ExampleLive Demo           jQuery Example                   $(document).ready(function(){          $("button").click(function(){             alert($("img").attr("height"));          });       });                               Get the height        

How to select a single element which matches the given ID using jQuery?

Amit D
Updated on 13-Feb-2020 09:38:48

349 Views

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 −ExampleLive Demo           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          

Is it possible to use $(this) and universal selector (*) with jQuery?

Alex Onsman
Updated on 13-Feb-2020 09:25:47

206 Views

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:ExampleLive Demo           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.          

How to combine a class selector and an attribute selector with jQuery?

Amit D
Updated on 13-Feb-2020 09:24:07

627 Views

A jQuery Selector is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria. We can easily combine a class selector and an attribute selector with jQuery.You can try to run the following code to learn how to How to combine a class selector and an attribute selector with jQuery −ExampleLive Demo                       $(document).ready(function() {          $('.myclass[reference="12345"]').css("background-color", "yellow");       });                                             Row 1 Column 1                                 Row 2 Column 1                                 Row 3 Column 1                    

How can I get the ID of an DOM element using jQuery?

Arnab Chakraborty
Updated on 22-Jun-2020 07:55:54

775 Views

In jQuery attr method is use to get the id attribute of the first matching element.$("btn1").attr("id")In your exampleExample iddom                 $(document).ready(function () {          $('#btn1').click(function () {             alert( $('#test').attr('id'));          });       });                   Click Here

How can I know which radio button is selected via jQuery?

Ricky Barnes
Updated on 13-Feb-2020 07:37:01

293 Views

Use the jQuery val() method to get the value of the selected radio button. You can try to run the following code to learn how to know which radio button is selected via jQuery −ExampleLive Demo           jQuery Selector                      $(function(){            $("#submit").click(function(){                     alert($('input:radio:checked').val());           });          });                              Select a number:          1          2          3          Result          

Advertisements