开发者

Simple jQuery problem

开发者 https://www.devze.com 2023-01-30 18:48 出处:网络
This one should be easy I\'ve got this HTML <table class=\"PageNumbers\"> <tr> <td colspan=\"3\">text3

This one should be easy

I've got this HTML

<table class="PageNumbers">
<tr>
    <td colspan="3">text3
    </td>
</tr>
<tr>
    <td colspan="2">text
    </td>
    <td>text2
    </td>
</tr>
<tr>
    <td>moretext
    </td>
    <td>moretext2
    </td>
<td>moretext3
    </td>
</tr>
</table>

I need to change the colspan of the first rows first column to one

This is what i've got

开发者_开发百科
$('.PageNumbers tr:first td:first').attr('colspan') = '1'

Doesn't seem to work though

Any ideas?

Thanks


You're really close I think. Try this.

$('.PageNumbers tr:first td:first').attr('colspan', '1');

Also, I think by specs class names are supposed to be lowercase? It shouldn't stop anything from working though.


Try this:

$('.PageNumbers tr:first td:first').attr('colspan', '1');


Here's another way:

$('.PageNumbers')[0].rows[0].cells[0].colSpan = 1;

or:

$('.PageNumbers')[0].rows[0].cells[0].setAttribute('colSpan', 1);


You can use this selector:

$('table.PageNumbers > tr:first > td:first').attr('colspan', '1');

Check out the jQuery selectors for more information :)


You should do this:

$('table.PageNumbers').find('tr:first td:first').attr('colspan', '1');


This should be the fastest.

$('.PageNumbers tr td').eq(0).attr('colspan',1);
0

精彩评论

暂无评论...
验证码 换一张
取 消