On Thu, Mar 26, 2009 at 4:01 AM, Ricardo <[email protected]> wrote:
>
> jQuery.fn.nextUntil = function(expr) {
>   var match = [];
>   this.each(function(){
>       for( var i = this.nextSibling; i; i = i.nextSibling ) {
>           if ( i.nodeType != 1 ) continue;
>           if ( jQuery.filter( expr, [i] ).r.length ) break;
>           match.push( i );
>       }
>   });
>   return this.pushStack( match, arguments );
> };
> (plugin by John Resig)
>
> $('h1').each(function(){
>  $(this).nextUntil('h1').wrapAll('div');
> });
>

Thanks for your answer. I missed this answer unfortunately, and first
today returned to this problem. Without seeing your reply I solved it
without jquery as follows:

    var headerList = document.getElementsByTagName("h1");
    for (var i = 0; i < headerList.length; i++) {
        if (i == headerList.length) {
            break;
        }
        var header = headerList[i];
        var nextHeader = headerList[i+1];
        var nextSibling = header.nextSibling;
        var div = document.createElement('div');
        div.id = "div-" + header.id;
        header.parentNode.replaceChild(div, header);
        div.appendChild(header);
        while (nextSibling != nextHeader) {
            var tmpSibling = nextSibling.nextSibling;
            var tmpParent = nextSibling.parentNode;
            tmpParent.removeChild(nextSibling);
            div.appendChild(nextSibling);
            nextSibling = tmpSibling;
        }
    }

Thanks for taking the time to answer

/Claes

Reply via email to