Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get td width

I want to learn with jQuery "td width", for an example:

if(td.width=="100"){
    alert("td width = 100");
}

Please explain.

<table width="200" border="1">
    <tr>
        <td width="100">Number</td>
        <td width="50">Order</td>
    </tr>
    <tr>
        <td width="100">1</td>
        <td width="50">Car</td>
    </tr>
</table>
like image 359
aldimeola1122 Avatar asked Feb 18 '23 13:02

aldimeola1122


2 Answers

here's a simple extension, the css could be edited to do something less intrusive.

var tdWidthLimit = 100;

$('td').each(function() {
    tdWidth = $(this).width();
    if (tdWidth >= tdWidthLimit)
    {    
        alert('hightlighted td width is ' + tdWidth);
        $(this).css({'background-color' : '#f00'});
    }
});

working demo here​

like image 113
Pete Uh Avatar answered Feb 21 '23 04:02

Pete Uh


$('td').each(function(){
      if($(this).width() == 100){
           alert(this.textContent + " width = 100");
      }
});

This will look through all your tds and then alert the td's text content and "width = 100" if the width is 100

like image 21
Anton Avatar answered Feb 21 '23 04:02

Anton