Found 10877 Articles for Web Development

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 multiple elements with jQuery?

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

313 Views

With jQuery, you can easily select multiple elements.  Here’s how you can select for multiple elements such as and ,$("h1, p")You can try to run the following code to learn how to select multiple elements with jQuery −ExampleLive Demo           jQuery Example                      $(document).ready(function() {             $("h1, p").css("color", "green");          });                                   Heading          This is demo text.              

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

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

244 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

86 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 use universal (*) selector in jQuery?

Amit D
Updated on 13-Feb-2020 09:25:02

194 Views

The universal selector selects all the elements available in the document. Here’s how to use it:$('*')ExampleYou can try to run the following code to learn how to implement Universal Selector in jQuery −Live Demo           jQuery Universal Selector                          $(document).ready(function() {             /* This would select all the elements */             $("*").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          

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

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

407 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 to find an element based on a data-attribute value using jQuery

Amit D
Updated on 13-Feb-2020 09:23:08

3K+ Views

To find an element based on a data-attribute value using jQuery is quite easy. Try to run the following code to find an element based on a data-attribute value −ExampleLive Demo    $(document).ready(function() {      $('[data-slide="0"]').addClass('demo');    }); .demo {     font-size: 150%;     color: red; } Rocky Amit John

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

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

529 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 to get selected text from a drop-down list (select box) using jQuery?

Ricky Barnes
Updated on 12-Jun-2020 12:50:48

758 Views

With jQuery, it’s easy to get selected text from a drop-down list with :selected. This is done using the select id. You can try to run the following code to learn how to get selected text from a drop-down list using jQuery −ExampleLive Demo           jQuery Selector                      $(document).ready(function() {             $("#submit").click(function(){                      $("#myselection option:selected").text();                alert( $("#myselection option:selected").text() );             });          });                              The selected value:                   First           Second                 Result              

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

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

163 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