Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing Colspan = "2" with Colspan = "4" using Jquery

Tags:

jquery

VenueID: 3

I want to replace first Colspan="2" with Colspan="4" in my first TR not in complete page using JQuery.

Thanks.

Best Regards, MS

like image 678
Manoj Singh Avatar asked Sep 08 '09 13:09

Manoj Singh


3 Answers

This jQuery should handle the condition of finding a td with colspan 2 in the first tr of any table and set its colspan to 4.

$("table tr:first td[colspan=2]").attr('colspan',4);

The better thing to do would be to just fix your HTML to produce colspan=4

like image 180
gnarf Avatar answered Sep 21 '22 20:09

gnarf


First of all, you forgot to close one of your <tr>'s. Second, you'll need a unique id or classname attached to that <td> to target it more easily. Third, use JQuery attr() method. Like this:

<tr>
     <td colspan="2" id="thatsmytd"></td>
</tr>

$('#thatsmytd').attr('colspan','4');
like image 40
n1313 Avatar answered Sep 22 '22 20:09

n1313


Use :first selector:

$("table tr:first")
like image 1
kgiannakakis Avatar answered Sep 20 '22 20:09

kgiannakakis