Found 766 Articles for JQuery

How do we use wildcard or regular expressions with a jQuery selector?

David Meador
Updated on 18-Dec-2019 08:27:41

1K+ Views

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:Live Demo $(document).ready(function(){    $("[id^=sub]").css("background-color", "green"); }); Java HTML Ruby

How do we use jQuery Attribute selector with a period?

Amit D
Updated on 18-Dec-2019 08:25:45

228 Views

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:Live Demo $(document).ready(function(){    $( "div[myattr*='.']" ).css("background-color", "yellow");   }); Java HTML Ruby

How to remove disabled attribute using jQuery?

Amit D
Updated on 18-Dec-2019 08:24:47

11K+ Views

To remove disabled attribute using jQuery, use the removeAttr() method. You need to first remove the property using the prop() method. It will set the underlying Boolean value to false.ExampleYou can try to run the following code to learn how to remove disabled attribute using jQuery:Live Demo $(document).ready(function(){     $('.disabledCheckboxes').prop("disabled", true);     $('.disabledCheckboxes').removeAttr("disabled");     $(document).ready(function(){         $('button').on('click', function() {           if (this.hasAttribute("disabled")) {              alert('The disabled attribute exists')           } else {              alert('The disabled attribute does not exist')           }         })     });  });    Result

How do we use # in jQuery Attribute Selector?

Amit D
Updated on 18-Dec-2019 08:21:18

249 Views

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:Live Demo     $(document).ready(function()  {        $( "div[myattr*='#']" ).css("background-color", "yellow");     }); Java HTML Ruby

How to set “checked” for a checkbox with jQuery?

Amit D
Updated on 18-Dec-2019 08:22:59

2K+ Views

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:Live Demo   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();  

How to use jQuery to get the value of HTML attribute of elements?

Amit D
Updated on 18-Dec-2019 08:20:27

200 Views

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:Live Demo                          $(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                            

How can I add an attribute into specific HTML tags in jQuery?

Amit D
Updated on 18-Dec-2019 08:19:15

904 Views

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:Live Demo   $(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    

How do I find a certain attribute exists or not for a selected item in jQuery?

Amit D
Updated on 18-Dec-2019 08:41:53

94 Views

To find a certain attribute exists or not for a selected item in jQuery, use the hasAttribute() method.ExampleYou can try to run the following code to learn how to find a certain attribute exists or not:Live Demo                          $(document).ready(function(){             $('button').on('click', function() {                 if (this.hasAttribute("myattr")) {                    alert('True - myattr attribute exists')                 } else {                    alert('False - myattr attribute does not exist')                 }             })          });                           Button One                   Button Two          

How to use *= operator in jQuery attribute selector?

Amit D
Updated on 18-Dec-2019 08:40:36

385 Views

The *= operator is used to filter elements for attribute containing the given value.ExampleYou can try to run the following code to learn how to *= operator to filter attributes on the basis of text:Live Demo $(document).ready(function(){    $( "div[myattr*='subject']" ).css("background-color", "yellow");     }); Java HTML Ruby

How to find an element based on a data-attribute value in jQuery?

Amit D
Updated on 18-Dec-2019 08:39:29

430 Views

To find an element based on a data-attribute value using jQuery is quite easy.ExampleYou can try to run the following code to learn how to find an element based on a data-attribute value using jQuery:Live Demo    $(document).ready(function() {       $('[data-slide="2"]').addClass('demo');    }); .demo {     font-size: 200%;     color: green; } One Two Three

Advertisements