Found 766 Articles for JQuery

How does $('iframe').ready() method work in jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:24:24

2K+ Views

Here’s an example wherein the iframe size is larger than the page. We will scroll to the top of the page whenever the iframe loads using jQuery −ExampleLive Demo               $(document).ready(function(){       $("button").click(function(){         $('iframe').ready(function(){           $(window).scrollTop(0);         });       });    });           Loop through each image

How to loop through all the iframes elements of a page using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:22:57

989 Views

To loop through all the iframes element of a page, use the jQuery each() method. You can try to run the following code to learn how to loop through all iframes. We have created three iframes below −ExampleLive Demo $(document).ready(function(){   $("button").click(function(){     $("iframe").each(function(){       alert($(this).text())       });   }); });   Qries Q/A   Tutorialspoint Free Learning   Send Files   Loop through iFrames

How to insert new row into table at a certain index using jQuery?

Kristi Castro
Updated on 20-Jun-2020 08:09:28

1K+ Views

To insert a new row into table at a certain index, use the jQuery val() and insertBefore() method. You can try to run the following code to learn how to insert new row into table −ExampleLive Demo     jQuery Example       $(document).ready(function(){               $('#index').val($('#myTable tbody tr').length);     $('#btn1').click(function(){       var indx = $('#index').val()-1;       var newRow = $('New row is added at index '+$('#myTable tbody tr').length+'');       newRow.insertBefore($('#myTable tbody tr:nth('+indx+')'));    });   });                   This is row 1                   This is row 2                 Add

How can I set the content of an iframe without src using jQuery?

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

1K+ Views

To set the content of an iframe without src, use the jQuery html() method. You can try to run the following code to learn how to set the content of an iframe without src attribute −ExampleLive Demo      jQuery Selector                  $(document).ready(function() {     var context = $('iframe')[0].contentWindow.document;     var $body = $('body', context);     $body.html('Hello World!');   });        

How to get the children of the $(this) selector in jQuery?

Kristi Castro
Updated on 20-Jun-2020 08:07:11

88 Views

To get the children of the $(this) selector, use the jQuery find() method. You can try to run the following code to get the children of the $(this) selector −ExampleLive Demo   jQuery Example       $(document).ready(function(){     $('#mydiv').click(function(){       alert($(this).find('img:last-child').attr('src'));    });   });   #my_div {    width: 200px;    height: 200px;    background-color: red;   }    

How to center a div on the screen using jQuery?

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

570 Views

To center a div on the screen, use the jQuery centering function jQuery.fn.center. You can try to run the following code to learn how to center a div on the screen:ExampleLive Demo               $(document).ready(function(){       jQuery.fn.center = function(parent) {         if (parent) {           parent = this.parent();         } else {           parent = window;         }       this.css({        "position": "absolute",        "top": ((($(parent).height() ... Read More

How to check if a div is visible using jQuery?

Arnab Chakraborty
Updated on 22-Jun-2020 07:58:38

11K+ Views

You can use .is(‘:visible’) selects all elements that are visible.Example divvisible               $(document).ready(function () {          $("button").click(function () {             var dim = $('#div1').is(":visible");             if (dim == false) {                $('#div1').css({ "display": "block", "color": "red" });             }          });       });     Div is visible    Click Here

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

Advertisements