문제

I have to create a thead using the first row from a tbody. I don't have full control of the markup so I'm using jQuery to do this.

I have been successful using some borrowed script but when I add more than one table to a page the first row seems to be being duplicated across the following tables

I would imagine that I need to target the parent table, normally I would give each table an ID but I cannot as these are generated for me.

an example of what's happening can be seen on this fiddle http://jsfiddle.net/FGH6B/

My current jquery is as follows

jQuery("document").ready( function() {

    var mytable = $("table"); 

    mytable.prepend(document.createElement('thead'));

    $("table thead").append($("tbody tr:eq(0)"));

});
도움이 되었습니까?

해결책

Try this:

$("document").ready( function() {
    $('table').each(function(){
    $(this).prepend('<thead></thead>')
    $(this).find('thead').append($(this).find("tr:eq(0)"));
})});

Working Demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top