Found 10711 Articles for Web Development

How to count number of columns in a table with jQuery

Kristi Castro
Updated on 20-Jun-2020 08:04:48

599 Views

To count number of columns in a table with jQuery, use the each() function with attr(). You can try to run the following code to learn how to count column in a table:EaxmpleLive Demo       jQuery Example             $(document).ready(function(){       var num = 0;       $('tr:nth-child(1) td').each(function () {         if ($(this).attr('colspan')) {           num += +$(this).attr('colspan');         } else {         num++;       }     });    alert("Total Columns= "+num); });         -1st column-     -2nd column-     -3rd column-    

How to count number of rows in a table with jQuery?

Arnab Chakraborty
Updated on 21-Jun-2020 17:04:04

1K+ Views

Example Live Demo table        table,th,td {       border:2px solid black;       margin-left:400px;    }    h2 {       margin-left:400px;    }    button {       margin-left:400px;    }            $(document).ready(function () {       $("button").click(function () {          var rowcount = $('table tr').length;          alert("No. Of Rows ::" +rowcount);       });    }); HTML TABLE NAME AGE DD 35 SB 35 AD 5 AA 5 Click Here

How can I tell if table row is in view using jQuery?

Kristi Castro
Updated on 20-Jun-2020 08:03:51

869 Views

To check if table row exists or not, use the is() method, with the :visible selector −if($(".row").is(":visible")) {   alert("Visible!"); }You can try to run the following code to learn how to chck if a row exists or not. It even notifies when a new row is created −ExampleLive Demo   jQuery - Add Table Rows     table{    width: 100%;    margin: 25px 0;    border-collapse: collapse;   }   table, th, td{    border: 1px solid #6C220B;   }   table th, table td{    padding: 8px;    text-align: left;   }   ... Read More

How to call a jQuery function after a certain delay?

Kristi Castro
Updated on 20-Jun-2020 08:02:01

5K+ Views

To call a jQuery function after a certain delay, use the siteTimeout() method. Here, jQuery fadeOut() function is called after some seconds.You can try to run the following code to learn how to work with setTimeout() method in jQuery to call a jQuery function after a delay −ExampleLive Demo         $(document).ready(function(){     $("#button1").bind("click",function() {       setTimeout(function() {         $('#list').fadeOut();}, 2000);     });   });                    Voice        Speak      Write         The above content will fade out after 2 seconds

How to make a jQuery function call after “X” seconds?

Kristi Castro
Updated on 20-Jun-2020 13:12:17

3K+ Views

To make a jQuery function call after “X” seconds, use the siteTimeout() method.On button click, set the following and fade out the element. Here, we have also set the milliseconds. This is the delay that would occur before fading an element:$("#button1").bind("click",function() {    setTimeout(function() {       $('#list').fadeOut();}, 4000); });You can try to run the following code to learn how to work with setTimeout() method in jQuery:Example Live Demo               $(document).ready(function(){          $("#button1").bind("click",function() {             setTimeout(function() {                $('#list').fadeOut();}, 4000);             });          });               India       US       UK     The above data will fade out after 4 seconds

How to determine if JavaScript object is an event?

Shubham Vora
Updated on 23-Aug-2022 08:49:40

1K+ Views

Let us first understand what is JavaScript objects and JavaScript events. An object in JavaScript is a distinct entity having properties and a type. For an instance, contrast it with a bowl. A bowl is an object with some properties. The properties are design, color, material, weight, etc. Like this, JavaScript object also has some properties. An independent entity known as a JavaScript object can store numerous values as its properties and methods. While a method represents a function, an object property maintains a literal value. Either the object literal or the object function object() { [native code] } syntax ... Read More

How to add a new row in a table using jQuery?

Kristi Castro
Updated on 20-Jun-2020 15:37:29

2K+ Views

Use event delegations to include both add a new and delete a table row on a web page using jQuery.Firstly, set a button in HTML to add new row    Add new Row Now under the button click event, set the code:$("#newbtn").click(function () { }Example Live Demo    $(document).ready(function(){       var x = 1;       $("#newbtn").click(function () {          $("table tr:first").clone().find("input").each(function () {             $(this).val('').attr({                'id': function (_, id) {                 ... Read More

How to check whether a string contains a substring in jQuery?

Kristi Castro
Updated on 20-Jun-2020 15:56:41

2K+ Views

The jQuery :contains() Selector is used to check whether a string contains a substring in jQuery.Set the substring you are searching for in the contains() method as shown below:$(document).ready(function(){    $("p:contains(Video)").css("background-color", "blue"); });Now, let us see the complete code to check whether a string contains a substring or not:Example Live Demo               $(document).ready(function(){          $("p:contains(Video)").css("background-color", "blue");       });     Tutorialspoint This is demo text. Free Tutorials Free Video Tutorials

How to make a textarea and input type read only using jQuery?

Kristi Castro
Updated on 20-Jun-2020 15:45:47

2K+ Views

To make a textarea and input type read only, use the attr() method .For readonly, set the input type text and textarea as read only as shown below:$('input[type="text"], textarea').each(function(){    $(this).attr('readonly','readonly'); });The following is the code to set readonly to textarea and input type:Example Live Demo jQuery Example               $(document).ready(function() {          $('input[type="text"], textarea').each(function(){             $(this).attr('readonly','readonly');          });       });     readonly textarea

How to disable/ enable checkbox with jQuery?

Kristi Castro
Updated on 20-Jun-2020 15:45:00

5K+ Views

fTo disable and enable checkbox, use the attr() method.Initially set the input type checkbox and disable it −MaleNow on the click of a button, toggle between disabled and enabled checkbox −$("#button1").click(function() {    $("#sName").attr('disabled', !$("#sName").attr('disabled')); });Example Live Demo jQuery Example               $(document).ready(function() {          $("#button1").click(function() {             $("#sName").attr('disabled', !$("#sName").attr('disabled'));          });       });     Male

Advertisements