www.webdeveloper.com
Results 1 to 2 of 2

Thread: How do you use javascript to copy and paste sections of html within a page?

  1. #1
    Join Date
    May 2013
    Posts
    2

    Question How do you use javascript to copy and paste sections of html within a page?

    I'm trying to make a greasemonkey script that displays all of the images and attachments within a forum post at the beginning of the post so I don't have to scroll past all of the comments and pages and pages to find the content. Essentially it would just copy sections of html and paste them at the top of the first page.

    For example:
    On this forum post: http://www.elva.com/forum/viewtopic.php?f=3&t=291
    pretend like it is 5 pages deep and has a mix of images and attachments. I want to display them all at the top of the first page. The first attachment is in div.attachcontent. I would want to copy all of the code within that, and paste it at the beginning of the thread using greasemonkey and javascript. How would I do that?

  2. #2
    Join Date
    May 2013
    Posts
    2
    This code works for the images:
    Code:
    var linkedthumbs = document.querySelectorAll("a > img");
    var pnew = document.createElement("p");
    for (var i=0; i<linkedthumbs.length; i++){
      var linkclone = linkedthumbs[i].parentNode.cloneNode(true);
      linkclone.innerHTML = linkedthumbs[i].outerHTML;
      pnew.appendChild(linkclone);
      pnew.appendChild(document.createTextNode(" "));
    }
    document.body.innerHTML = "";
    document.body.appendChild(pnew);
    but I can't figure out how to append the page links. The page links are in div.pagination if that helps. I just want the contents of div.pagination shown at the top of the pages, followed by the images. Everything I try so far hasn't worked.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles