Mark Fondy
Mark Fondy

Reputation: 3923

Rowspan with jQuery?

<table>
    <tr><td>aaa</td><td id="one" max="3">aaa</td><td>aaa</td><td>aaa</td></tr>
     <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr>
     <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr>
     <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr>
</table>

table td {
    padding: 3px;
    border:solid 2px red;
    }

I would like receive using only jQuery this:

<table>
    <tr><td>aaa</td><td rowspan="3">aaa</td><td>aaa</td><td>aaa</td></tr>
     <tr><td>aaa</td><td>aaa</td><td>aaa</td></tr>
     <tr><td>aaa</td><td>aaa</td><td>aaa</td></tr>
     <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr>
</table>

Attribute max == rowspan. Is this possible?

LIVE: http://jsfiddle.net/fKQSz/

Upvotes: 0

Views: 2147

Answers (2)

user1106925
user1106925

Reputation:

You could do it like this:

var start = $('#one');
var n = start.attr('max');
start = start.prop('rowspan',n).parent();
var idx = start.index();

while(--n) {
    start = start.next();
    start.children().eq(idx).remove();
}

http://jsfiddle.net/fKQSz/4/

Upvotes: 2

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324630

Erm... so you want:

var td = document.getElementById('one');
td.setAttribute("colspan",td.getAttribute("max"));

Is that it?

Upvotes: 0

Related Questions